I am trying to explicitly instantiate a templated function of type U inside a templated class of type T. My code below generates a warning and the linker does not find the explicit instantiation of ReinterpretAs()
. Can anyone spot the error or advise on how to do this? I am using VC++ 2010.
template<typename T>
class Matrix
{
public:
template<typename U> Matrix<U> ReinterpretAs() const;
};
template<typename T>
template<typename U>
Matrix<U> Matrix<T>::ReinterpretAs() const
{
Matrix<U> m;
// ...
return m;
}
// Explicit instantiation.
template class Matrix<int>;
template class Matrix<float>;
template Matrix<float> Matrix<int>::ReinterpretAs<float>();
template Matrix<int> Matrix<float>::ReinterpretAs<int>();
The last two lines above give a compiler warning:
warning #536: no instance of function template "Matrix<T>::ReinterpretAs
[with T=float]" matches the specified type
Thank you in advance, Mark
You're missing the const
.
template class Matrix<int>;
template class Matrix<float>;
template Matrix<float> Matrix<int>::ReinterpretAs<float>() const;
template Matrix<int> Matrix<float>::ReinterpretAs<int>() const;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With