I am making program in which I create class for vector and overload different operators. Now I want to make arguments of vector (coordinates) as templates. When I have all code in one file everything is alright and program is running correctly:
#ifndef VECTOR4D_H_INCLUDED
#define VECTOR4D_H_INCLUDED
template <typename TYPE>
class VECTOR4D{
public:
VECTOR4D (void): X(0), Y(0), Z(0), T(0){};
VECTOR4D (TYPE X, TYPE Y, TYPE Z, TYPE T): X(X), Y(Y), Z(Z), T(T){};
TYPE X, Y, Z, T;
VECTOR4D &operator+=(VECTOR4D &K){
this->X += K.X;
this->Y += K.Y;
this->Z += K.Z;
this->T += K.T;
return *this;
}
};
#endif // VECTOR4D_H_INCLUDED
but when I separate implementation and declaration of overload operator I have a problem.
//vector4d.h
#ifndef VECTOR4D_H_INCLUDED
#define VECTOR4D_H_INCLUDED
template <typename TYPE>
class VECTOR4D{
public:
VECTOR4D (void): X(0), Y(0), Z(0), T(0){};
VECTOR4D (TYPE X, TYPE Y, TYPE Z, TYPE T): X(X), Y(Y), Z(Z), T(T){};
TYPE X, Y, Z, T;
VECTOR4D &operator+=(VECTOR4D &);
};
#endif // VEKTOR4D_H_INCLUDED
//project.cpp
#include <iostream>
#include "vector4d.h"
VECTOR4D &VECTOR4D::operator+=(VECTOR4D &K)
{
this->X += K.X;
this->Y += K.Y;
this->Z += K.Z;
this->T += K.T;
return *this;
}
During compilation i have got an error:
invalid use of template-name 'VECTOR4D' without an argument list
How I have to do this to make it correct?