0

このコードから次のエラーが発生します: エラー 1 エラー LNK2019: 未解決の外部シンボル "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class Point const &)" (??6 @YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Point@N@@@Z) 関数 _main で参照 G:\C++ Part II\Final Exam\Point\Point \Source.obj ポイント

このエラーは通常、関数が定義されていないことを意味しますが、関数は定義されています。main の cout ステートメントをコメント アウトすると、プログラムはコンパイルされます。テンプレートの指定に何か不足していると思いますか?

#include <iostream>
using namespace std;

template <class T>
class Point{
private:
T x, y;

public:
Point(): x(0), y(0) {cout << "Default Constructor\n";};
Point(T a, T b): x(a), y(b) {cout << "Parameterized Constructor\n";};
Point(const Point &rhs);
~Point() {cout << "Destructor\n";};
friend ostream &operator<<(ostream &os, const Point<T> &X);

};

int main(){
Point <double> B;
cout << B << endl;

return 0;
}
template <class T>
Point<T>::Point(const Point &rhs)
{
x = rhs.x;
y = rhs.y;
cout << "Copy Constructor\n";
}
template <class T>
ostream &operator<<(ostream &os, const Point<T> &X)
{
os << "(" << X.x << ", " << X.y << ")";

return os;
}
4

1 に答える 1