プライベートフィールドにアクセスする必要があるクラステンプレートとオペレータテンプレートがあります。私は、テンプレートの友人作ることができます。オペレータのフレンド固有のテンプレートのインスタンス
template <typename T>
class A {
int x;
template <typename U>
friend bool operator==(const A<U>& a, const A<U>& b);
};
template <typename T>
bool operator== (const A<T>& a, const A<T>& b) {
return a.x == b.x;
}
int main() {
A<int> x, y;
x == y;
return 0;
}
をしかし、それはA<T>
のみoperator==<T>
友人を作り、A<double>
のoperator==<int>
友人をしていないすることは可能でしょうか?
http://ideone.com/vnu3QRを動作していないよう – RiaD
これはコンパイラのバグではありません。その構文が有効な場所がありますが、これはその1つではありません。 –
@AlanStokesですが、この構文は完全に有効です。どうしてあなた自身を試してみませんか?クラスの前に 'operator =='を入れてください。 – ixSci