The following code compiles.
matrix.h before template
template<typename T>
class Matrix
{
public:
//...
unique_ptr<Matrix<T>> Test() const;
};
matrix.cpp before template
template<typename T>
unique_ptr<Matrix<T>> Matrix<T>::Test() const
{
unique_ptr<Matrix<T>> a{ new Matrix<T>{ 1, 1 } };
return std::move(a);
}
I wanted to use a typedef (using) to shorten things as I thought it'd be more readable but my changes cause errors. Here are the relevant changes.
matrix.h after template
template<typename T>
class Matrix
{
public:
//...
MatrixUniq<T> Test() const;
};
template<class T> using MatrixUniq = unique_ptr<Matrix<T>>;
matrix.cpp after template
template<typename T>
MatrixUniq<T> Matrix<T>::Test() const
{
MatrixUniq<T> a{ new Matrix<T>{ 1, 1 } };
return std::move(a);
}
Compiling after these changes are made crashes the VC++ compiler twice, but also generates a few errors:
Error C2143 syntax error: missing ';' before '<'
Error C4430 missing type specifier - int assumed.
Error C2238 unexpected token(s) preceding ';'
Error C1903 unable to recover from previous error(s);
What's wrong with my typedef implementation? Thanks.
Edit: I'm using VS2015. I'm building a static library. At the bottom of matrix.cpp I have:
template class VMatrix<double>;