首先,我的代碼在matrix.hpp
一個片段:爲什麼其中一個模板靜態函數有效,另一個不是?
template <class T>
class matrix
{
public:
matrix();
T& operator() (size_t i, size_t j) {return elem[i+j*4];}
const T& operator() (size_t i, size_t j) const {return elem[i+j*4];}
// ...
static matrix<T> identity() {return matrix<T>();}
static matrix<T> translation(const vector<T>&);
template <class RT> static matrix<T> rotation_x(RT);
// ...
};
// ...
template <class T>
inline
matrix<T>
matrix<T>::translation(const vector<T>& v)
{
matrix<T> result;
result(0, 3) = v.x;
result(1, 3) = v.y;
result(2, 3) = v.z;
return result;
}
template <class T, class RT>
inline
matrix<T>
matrix<T>::rotation_x(RT angle)
{
RT ca = std::cos(angle);
RT sa = std::sin(angle);
matrix<T> result;
result(1, 1) = +ca;
result(1, 2) = -sa;
result(2, 1) = +sa;
result(2, 2) = +ca;
return result;
}
據我所知,這兩個實現沒有太多技術上的不同。主要的區別是,rotation
使用一個額外的模板參數相比translation
然而,G ++不接受rotation
我現在有它的方式:
la/matrix.hpp:272:31: error: invalid use of incomplete type 'class la::matrix<T>'
la/matrix.hpp:16:7: error: declaration of 'class la::matrix<T>'
這是怎麼回事?
尤其適用於模板發佈完成錯誤。 – tuxuday