あなたは本当にこれをしたくありません。値へのポインターではなく、値の演算子を定義する標準的な方法に固執することで、すべてがよりクリーンになり、保守が容易になります。
EDIT ascheplerがコメントで指摘しているように、これを行うことさえできません。引数の少なくとも 1 つは、クラス型またはクラスへの参照である必要があります。
大規模なコピー操作を回避したい場合は、C++11 の移動セマンティクスを使用するMoveProxy
か、Boost.Moveサポート ライブラリなどを使用してそれらをエミュレートする必要があります。
コード例:
// loads of memory with deep-copy
struct X {
int* mem;
X() : mem(new int[32]) { }
// deep-copy
X(const X& other)
: mem(new int[32]) { std::copy(other.mem, other.mem+32, this.mem); }
~X() { delete[] mem; }
X& operator=(const X& other) { std::copy(other.mem, other.mem+32, this.mem); return *this; }
X(X&& other) : mem(other.mem) { other.mem = nullptr; }
X& operator=(X&& other) { delete[] mem; this.mem = other.mem; other.mem = nullptr; return this; }
friend void swap(const X& x, const X& y)
{ std::swap(x.mem, y.mem); }
friend
X operator*(const X& x, const X& y)
{ return X(); }
};