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.

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.

commented: Thanks a lot Fbody! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.