“2 overloadshave no legal conversion for 'this' pointer”错误
——《深度探索C++对象模型》读书札记系列
问题:P101的代码,如下,编译出现“2 overloads have nolegal conversion for 'this' pointer”错误。
class Point2d {
public:
Point2d(float x = 0.0, float y = 0.0)
: _x(x), _y(y) {};
float x() { return _x; }
float y() { return _y; }
void x(float newX) { _x = newX; }
void y(float newY) { _y = newY; }
void operator+=(const Point2d& rhs)
{
_x += rhs.x();
_y += rhs.y();
}
protected:
float _x, _y;
};
class Point3d : public Point2d {
public:
Point3d(float x = 0.0, float y = 0.0, float z = 0.0)
: Point2d(x, y), _z(z) {};
float z() { return _z; }
void z(float newZ) { _z = newZ; }
void operator+=(const Point3d& rhs)
{
Point2d::operator+=(rhs);
_z += rhs.z();
}
protected:
float _z;
};