Good day people.
I have been given an assigment in which I must implement a Matrix class with an iterator-like structure over it. So, I have the following nested class:
template <class T>
class Matrix{
public:
(... stuff)
class Handler{
public:
(...more stuff)
};
(...even more stuff)
}
But when I try to run the following function, I get a "Can't deduce parameter 'T' ":
template <class T>
Matrix<T> multiplicar_matrices(typename Matrix<T>::Handler * m1,
typename Matrix<T>::Handler * m2){ return Matrix<T>(1,1);}
int main(){
Matrix<int>* a1 = new Matrix<int>(1,1);
typename Matrix<int>::Handler h1 = (*a1).getHandler();
Matrix<int>* a2 = new Matrix<int>(1,1);
typename Matrix<int>::Handler h2 = (*a2).getHandler();
multiplicar_matrices(&h1,&h2);
return 0;
}
What's weird is that the following DOES work:
Matrix<int> multiplicar_matrices(typename Matrix<int>::Handler * m1,
typename Matrix<int>::Handler * m2){return Matrix<int>(1,1);}
int main(){
Matrix<int>* a1 = new Matrix<int>(1,1);
typename Matrix<int>::Handler h1 = (*a1).getHandler();
Matrix<int>* a2 = new Matrix<int>(1,1);
typename Matrix<int>::Handler h2 = (*a2).getHandler();
multiplicar_matrices(&h1,&h2);
return 0;
}
So apparently the compiler DOES KNOW that h1 and h2 are "Matrix::Handler", it just refuses to acknowledge that during the Template creation. (which is weird, shouldn't Template just instance it with every possible class? why isn't it instancing with int?)
I don't understand why it's not being able to deduce the parameter 'T'.
Every piece of help is appreciated.
P.S. I am fully aware there are potential workarounds, such as defining the "mutiplicar_function" inside the Handler class. But I may be asked why I failed to do it the other way, so I need to understand what's going on here.