Hello all,

I would be grateful for some help with a function template problem.

I cannot figure out how to pass a matrix as an argument in a template function. I keep getting the error "does not match any template declaration". Can anyone suggest what my problem is? Have I written the argument incorrectly?

I have:

template <typename T>
void showMatrix(T** someMatrix)
   // stuff to do

Here's how I call it:

showMatrix( myMatrix );

The reason I need to pass the matrix as templatized is that I have a class for creating matrices (class Matrix) and I ALSO have matrices that are created as dynamic arrays, for example:

double ** matrix;
matrix = new double *[xDimension];
for (i = 0; i < xDimension; i ++)
matrix[i] = new double *[yDimension];

myMatrix (the one I use in my main() function call) is a dynamic array.

Thanks a lot.

Edited by RobBobSmith: n/a

6 Years
Discussion Span
Last Post by Fbody

Try taking out the "splats"...

template <typename T> void showMatrix(T someMatrix);

With them, you are effectively creating a pointer with 4-levels of indirection. A 2-d array (matrix) only has 2-levels of indirection and those should come over to the template with the array/matrix.

Edited by Fbody: n/a

Votes + Comments
Thanks a lot Fbody!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.