- 583 名前:デフォルトの名無しさん mailto:sage [2009/10/10(土) 21:21:55 ]
- 宜しくお願いします。このコードをコンパイルしますと
error C2664: 'Point<T>::set' : 1 番目の引数を 'int' から 'int &' に変換できません。 参照を外すと、静的でないメンバ関数の呼び出しが正しくありません。となります。 どのように対処したらいいのでしょうか? #include <iostream> using namespace std; template<class T> class Point { template<class> friend class Point; private: T x_; // x座標 T y_; // y座標 public: Point(); template <class U> Point(const Point<U>& r) : x_(r.x_), y_(r.y_){} Point(T x = T(), T y =T()) : x_(x), y_(y) {} void set(T& x, T& y); }; template<class T> void set(T& x, T& y) { x_ = x; y_ = y; } int main() { Point<int> ip(12, 34); Point<long> lp(ip); Point<int>::set(12, 34); // ここで当該エラー return 0; }
|

|