I have two classes set up as follows:
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();
};
Now whenever I try to do something like:
Vector v;
printf("%d\n", v[0]);
I get:
error: ‘Point’ is not an accessible base of ‘Vector’
error: ‘double& Point::operator[](unsigned int)’ is inaccessible
error: within this context
Why?
twice as large, heavy, strong, etc.; twofold in size, amount, number, extent, etc.: a double portion; a new house double the size of the old one. composed of two like parts or members; twofold in form; paired: double doors; a double sink. of, relating to, or suitable for two persons: a double room.
Class inheritance is by default private. You must explicitly tell the compiler that you want public inheritance:
class Vector : public Point { // public
public:
Vector(double x, double y, double z);
~Vector() {};
double norm();
void normalize();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With