我有我的类简单的操作符重载C++使用“*”运营商没有运营商这些操作数相匹配
class Vec2
{
public:
Vec2(float x1,float y1)
{
x = x1;
y = y1;
}
float x;
float y;
};
class FOO {
private:
friend Vec2 operator*(const Vec2 &point1, const Vec2 &point2)
{
return Vec2(point1.x * point2.x, point1.y * point2.y);
}
Vec2 mul(Vec2 p);
};
Vec2 FOO::mul(Vec2 p)
{
Vec2 point = p * Vec2(1,-1);
return point;
}
但这个乘法给了我这个错误:
operator*
no operator matches these operands
的问题是,我可以” t改变Vec2类,所以我需要全球运营商超载
为什么你在'class FOO'里面为'Vec2'重载'*'? –
我想使用FOO内的*运算符 – user63898
这是什么意思?在哪里写?在标题? – user63898