multiple inheritance
Posted
by hitech
on Stack Overflow
See other posts from Stack Overflow
or by hitech
Published on 2010-03-24T21:37:29Z
Indexed on
2010/03/24
21:53 UTC
Read the original article
Hit count: 183
c++
when we say "a member declated as protected is accessible to any class imediately derived from it" what does this mean. in the follwing example get_number function can be accessible by the result class , as per the statement it sould only be accessile to test class.
class student
{
protected:
int roll_number;
public:
void get_number(int){ cout<< "hello"; }
void put_number(void) {cout<< "hello"; }
};
class test : public student
{
protected :
float sub1;
float sub2;
public:
void get_marks(float, float) {cout<< "hello"; roll_number = 10; }
void put_marks(void) {cout<< "hello"; cout << "roll_number = " << roll_number ; }
};
class result :public test
{
float total;
public:
void display(){cout<< "hello"; roll_number = 10; }
};
int main()
{
result student;
student.get_marks(2.2, 2.2);
student.put_marks();
return 0;
}
i changed the code as per the first statement the protected variable roll_number not be accessible upto the result class ?
© Stack Overflow or respective owner