我以为我遵循了其他线程的逻辑,但是
namespace Geometry {
class Vector2D {
public:
Vector2D(float x_, float y_) : x(x_), y(y_) {}
float x;
float y;
}
Vector2D operator+(const Vector2D &lhs, const Vector2D &rhs) {
return Vector2D(lhs.x + rhs.x, lhs.y + rhs.y);
}
}
没有编译,我收到错误
error: no matching constructor for initialization of 'class Vector2D'
Vector2D operator+(const Vector2D &lhs, const Vector2D &rhs) {
error: expected ';' after top level declarator
Vector2D operator+(const Vector2D &lhs, const Vector2D &rhs) {
所以编译器似乎认为我的运算符在二进制' +'是一个变量的延期?
答案 0 :(得分:3)
啊,你错过了一个分号!