int a, b, c;
//do stuff. For e.g., cin >> b >> c;
c = a + b; //works
c = operator+(a,b); //fails to compile, 'operator+' not defined.
一方、これは機能します-
class Foo
{
int x;
public:
Foo(int x):x(x) {}
Foo friend operator+(const Foo& f, const Foo& g)
{
return Foo(f.x + g.x);
}
};
Foo l(5), m(10);
Foo n = operator+(l,m); //compiles ok!
- プリミティブ型(intなど)のoperator +(およびその他の演算子)を直接呼び出すことも可能ですか?
- はいの場合、どのように?
- そうでない場合、これが実行可能ではないことを明確にするC ++参照の言い回しはありますか?