Reputation: 524
I am currently designing a templated Vector2 class, for my game engine.
In order to keep everything tidy, I have been separating the function declarations and definitions. This was working fine with the constructors, however, I get the following error when trying to the same with a static function:
error C2244: 'spl::Vector2<T>::Dot' : unable to match function definition to an existing declaration
1> definition
1> 'T spl::Vector2<T>::Dot(const spl::Vector2<L> &,const spl::Vector2<R> &)'
1> existing declarations
1> 'T spl::Vector2<T>::Dot(const spl::Vector2<L> &,const spl::Vector2<R> &)'
What I am finding unusual is that despite the fact that the declaration and definition are identical, the compiler fails to match them.
Here is my Vector2 class:
// The Vector2 Class
template <typename T>
class Vector2{
public:
// Constructor
Vector2 ();
Vector2 (T Value);
Vector2 (T XAxis, T YAxis);
// Static Functions
template <typename L, typename R>
static T Dot (const Vector2 <L>& LHS, const Vector2 <R>& RHS);
// Variables
T x, y;
};
And here is the function declaration that sits just below it:
// Return The Dot Product Of Two Vectors
template <typename T, typename L, typename R>
T Vector2 <T>::Dot (const Vector2 <L>& LHS, const Vector2 <R>& RHS){
T xAxis = (T) LHS.x * (T) RHS.x;
T yAxis = (T) LHS.y * (T) RHS.y;
return (xAxis + yAxis);
}
If anyone knows why this error is being thrown and how to fix it, I will be forever in your debt.
P.S. I am using Visual Studio 2013 Ultimate, on a Windows 8.1 machine.
Upvotes: 0
Views: 453
Reputation: 206727
The syntax needs to be:
template <typename T>
template <typename L, typename R>
T Vector2 <T>::Dot (const Vector2 <L>& LHS, const Vector2 <R>& RHS){
T xAxis = (T) LHS.x * (T) RHS.x;
T yAxis = (T) LHS.y * (T) RHS.y;
return (xAxis + yAxis);
}
Upvotes: 2