I have a class I'm working on that deals with inheritance but I have a problem that is giving me a headache... I am trying to inherit members of the base class but no matter what I do the compiler tells me that "the member is inaccessible". Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class house{
protected:
int coordinateX;
int coordinateY;
int coordinateZ;
public:
void setCoordinates(int x, int y, int z){
coordinateX = x;
coordinateY = y;
coordinateZ = z;
}
};
class x3y2z1: public house{
};
On line 12 of the second block of code, I get an error saying that coordinateX is inaccessible. Can anybody tell me how to fix this? I've tried everything that I know and googled the problem.
Please help if you can.
EDIT:: Edited to fix a stupid mistake. The problem still applies.
"private" means that the data members are directly accessible only to the class in which they are declared (house). "protected" means that the data members are directly accessible to the class in which they are declared AND derived classes (x3y2z1). "public" means that the data members are directly accessible to the class in which they are declared, derived classes, AND all other code as well.
Hi kultrva. Like jsmith said, protected members are only accesible from the class where they were defined and from classes derived from it. You only have to create a getter function member.