Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Function templates

I have 2 2D arrays that represent a maze

const char maze1[10][11] and const char maze2[20][21]

I'm trying to create 1 function to handle both mazes like so:

void solveMaze(maze[][])
{
}

and just pass the maze like solveMaze(maze1);

How would I do this with function templates?

I recently asked this question already but explicitly asked not to use function templates because I wasn't sure on how to use it, but I would like to see how it would work. (hope this isn't "abusing" the system)

like image 226
dukevin Avatar asked Jun 20 '26 14:06

dukevin


1 Answers

You do not need and should not use templates to solve this problem. All you are doing is solving mazes of different sizes.

Templates are for the generation of a number of classes/functions that use various types.

Instead construct a class to store a maze. This class should store the dimentsions of the maze and give access to the components of that maze.

like image 107
Ed Heal Avatar answered Jun 22 '26 05:06

Ed Heal