2010-10-04 87 views
0

我有一个模板类,我米试图显式实例的显式模板实例:C++操作

template<T> 
struct tmat2x3 
{ 
... 
typedef tvec3<T> col_type; 
.. 
}; 

操作声明如下:

template <typename T> 
typename tmat2x3<T>::row_type operator* (tmat2x4<T> const & m, typename tmat2x3<T>::col_type const & v); 

我明确实例化操作使用以下内容:

template tmat2x3<unsigned char>::row_type operator * (tmat2x3<unsigned char> const &m, tmat2x3<unsigned char>::col_type const &s); 

gcc给我以下错误:但是:

../glm/glm_core.cpp: In instantiation of ‘typename glm::detail::tmat2x3<T>::row_type glm::detail::operator*(const glm::detail::tmat2x3<T>&, const typename glm::detail::tmat2x3<T>::col_type&) [with T = unsigned char]’: 
../glm/glm_core.cpp:443: instantiated from here 
../glm/glm_core.cpp:443: error: explicit instantiation of ‘typename glm::detail::tmat2x3<T>::row_type glm::detail::operator*(const glm::detail::tmat2x3<T>&, const typename glm::detail::tmat2x3<T>::col_type&) [with T = unsigned char]’ but no definition available 

关于我在做什么的任何想法是错误的?

在此先感谢

+0

当您明确实例化时,您是否有可用的body off操作符? – Anycorn 2010-10-04 01:14:29

+2

你已经向我们展示了这个声明,但编译器正在抱怨这个定义。你如何定义模板? – Potatoswatter 2010-10-04 01:31:10

回答

0

下面的代码编译并在VS2008。我相信问题是我们可以在您的运营商声明中看到的错误标识符tmat2x4

template < typename T > struct tmat2x3{ 
    typedef vector<T> col_type; 
}; 

template <typename T> typename tmat2x3<T>::col_type operator* (tmat2x3<T> const & m, typename tmat2x3<T>::col_type const & v); 

template <> tmat2x3<unsigned char>::col_type operator * (tmat2x3<unsigned char> const &m, tmat2x3<unsigned char>::col_type const &s){ 
    return tmat2x3<unsigned char>::col_type(); 
} 

int main(int argc, char ** argv){ 
    tmat2x3<unsigned char> blah; 
    blah * vector<unsigned char>(); 
    return 0; 
} 
+0

我更正了错字,但是您的代码并未强制独立模板实例化,它只能用作常规模板。 – kinzeron 2010-10-04 01:27:31

+2

这是一个专业化,而不是一个实例化。 – Potatoswatter 2010-10-04 01:30:31

0

我认为正在发生的事情是,你明确的实例,但编译器查找到页眉和无法找到应该实例化的代码。看看操作员实际上是为那种类型实现的。

0

确实问题出在定义上,现在编译好了。