と値Vector2
を格納するために使用する単純な Template クラスを作成しました。現在、ソースファイルにテンプレートの実装を保持しようとしていますが、演算子のオーバーロードでこれを行うことができませんX
Y
class Vector2
{
public:
Vector2<Type>();
Vector2<Type>(Type x, Type y);
Vector2<Type>(const Vector2<Type> &v);
~Vector2<Type>();
Vector2<Type> operator+ (const Vector2<Type> &other)
{
return Vector2<Type>(x + other.x, y + other.y);
}
private:
Type x, y;
};
現在、これはコンパイルされて正常に動作しますが、現在、これはヘッダー ファイルにあります。コンストラクターとデコンストラクターの実装もVector2
完全に正常に機能しますが、次のことを試してみると:
.h:
Vector2<Type> operator+ (const Vector2<Type> &other);
.cpp:
template <class Type>
Vector2<Type>::operator+ (const Vector2<Type> &other)
{
return Vector2<Type>(x + other.x, y + other.y);
}
コンパイラは私に言います:
missing type specifier - int assumed. Note C++ does not support default-int
よろしく、私