发布于 2010-08-19 20:36:15
你得让两者都超负荷。
但是,如果颠倒顺序,则可以重用代码:
struct foo
{
// this is the "core" operation, because it's mutating (changes this)
foo& operator+=(const foo&)
{
// ...
return *this;
}
};
foo operator+(const foo& lhs, const foo& rhs)
{
foo ret = lhs;
ret += rhs;
return ret;
}你做一个副本,操作那个副本,然后把它还给我。
https://stackoverflow.com/questions/3525965
复制相似问题