I am trying to write a generalized vector class of size and type for mathematical programming. I have problems with partial specialization.
The problem occurs when I try to specialize a member method of my vector class for a given size.
I can give a simple example:
template <size_t Size, typename Type> class TestVector { public: inline TestVector (){} TestVector cross (TestVector const& other) const; }; template < typename Type > inline TestVector< 3, Type > TestVector< 3, Type >::cross (TestVector< 3, Type > const& other) const { return TestVector< 3, Type >(); } void test () { TestVector< 3, double > vec0; TestVector< 3, double > vec1; vec0.cross(vec1); }
When I try to compile this simple example, I get a compilation error indicating that the specialization "cross" does not match the existing declaration:
error C2244: 'TestVector<Size,Type>::cross' : unable to match function definition to an existing declaration see declaration of 'TestVector<Size,Type>::cross' definition 'TestVector<3,Type> TestVector<3,Type>::cross(const TestVector<3,Type> &) const' existing declarations 'TestVector<Size,Type> TestVector<Size,Type>::cross(const TestVector<Size,Type> &) const'
I tried to declare a cross as a pattern:
template <size_t Size, typename Type> class TestVector { public: inline TestVector (){} template < class OtherVec > TestVector cross (OtherVec const& other) const; }; template < typename Type > TestVector< 3, Type > TestVector< 3, Type >::cross< TestVector< 3, Type > > (TestVector< 3, Type > const& other) const { return TestVector< 3, Type >(); }
This version passes the compilation, but does not work in link-time:
unresolved external symbol "public: class TestVector<3,double> __thiscall TestVector<3,double>::cross<class TestVector<3,double> >(class TestVector<3,double> const &)const
What am I missing here? Thanks, Florent