フレンド関数を使用して<<とテンプレートをオーバーロードし、テンプレートに慣れようとしています。これらのコンパイルエラーが何であるかわかりません:
Point.cpp:11: error: shadows template parm 'class T'
Point.cpp:12: error: declaration of 'const Point<T>& T'
このファイルの場合
#include "Point.h"
template <class T>
Point<T>::Point() : xCoordinate(0), yCoordinate(0)
{}
template <class T>
Point<T>::Point(T xCoordinate, T yCoordinate) : xCoordinate(xCoordinate), yCoordinate(yCoordinate)
{}
template <class T>
std::ostream &operator<<(std::ostream &out, const Point<T> &T)
{
std::cout << "(" << T.xCoordinate << ", " << T.yCoordinate << ")";
return out;
}
私のヘッダーは次のようになります:
#ifndef POINT_H
#define POINT_H
#include <iostream>
template <class T>
class Point
{
public:
Point();
Point(T xCoordinate, T yCoordinate);
friend std::ostream &operator<<(std::ostream &out, const Point<T> &T);
private:
T xCoordinate;
T yCoordinate;
};
#endif
私のヘッダーも警告を出します:
Point.h:12: warning: friend declaration 'std::ostream& operator<<(std::ostream&, const Point<T>&)' declares a non-template function
理由もわかりませんでした。何かご意見は?ありがとう。