views:

113

answers:

3

Hi,

I have a template class that I m trying to explicitly instantiate:

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

the operator is declared as follows:

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

I am explicitly instantiating the operator using the following:

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

gcc gives me the following error however:

../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 

Any idea on what I am doing wrong ?

Thanks in advance

A: 

The following code does compile on VS2008. I believe that the problem is the wrong identifier tmat2x4 that we can see on your operator declaration.

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;
}
tibur
i corrected the typo, but your code does not force a stand alone template instantiation, it only acts as a regular template.
kinzeron
That's a specialization, not an instantiation.
Potatoswatter
A: 

I think what is happening is that you're explicitly instantiating it, but the compiler is looking up into the headers and cant find the code that should get instantiated. Look to see that the operator actually is implemented for that type.

Jared Grubb
A: 

Indeed the problem was with the definition, now it's compiling ok.

kinzeron