我有两个类设置如下:
class Point {
protected:
double coords[3];
public:
Point(double x, double y, double z) {
setX(x);
setY(y);
setZ(z);
};
~Point() {};
double x() {return coords[0];};
double y() {return coords[1];};
double z() {return coords[2];};
void setX(double x) {
coords[0] = x;
};
void setY(double y) {
coords[1] = y;
};
void setZ(double z) {
coords[2] = z;
};
double &operator[](unsigned int x) {
return coords[x];
}
};
class Vector:Point {
public:
Vector(double x, double y, double z);
~Vector() {};
double norm();
void normalize();
};
现在每当我尝试做类似的事情时:
Vector v;
printf("%d\n", v[0]);
我得到:
error: ‘Point’ is not an accessible base of ‘Vector’
error: ‘double& Point::operator[](unsigned int)’ is inaccessible
error: within this context
为什么?