【发布时间】:2016-03-28 17:13:32
【问题描述】:
我有一个 vec2 类,定义如下
class vec2 {
public:
float x, y;
...
//add a scalar
vec2 operator+(float s) const {
return vec2(this->x + s, this->y + s);
}
};
operator+ 重载在执行 vec2 v = otherVector * 2.0f; 时效果很好,但在向后执行时不起作用,例如 vec2 v = 2.0f * otherVector;。
解决办法是什么?
【问题讨论】:
标签: c++