Subclass Data Visibility

Is a default visibility member of a subclass visible to methods of another subclass derived from the same base type? What about protected?

e.g.

1
2
3
4
5
6
7
8
9
10
11
class BaseClass{};
class SubClass1 : public BaseClass
     int x;
  protected:
     int y;
};
class SubClass2 : public BaseClass
{};

If I have some method in SubClass2 that is passed a BaseClass as an argument, can that method perform the assignment x=4 or y=4?
Hi CodingInBlue,

Private means that variable can be used by the functions in that class only. And not by an object of that class.

Protected is similar except that classes derived from it are also able to use the protected variable, via their functions. Conceptually, the derived class inherits the protected variables.

Topic archived. No new replies allowed.