![]() |
Why this code is not working?
CASE 1: Following code is not working...saying
error: `int Base::j' is protected error: within this context Code:
#include<iostream.h>CASE 2: This code works fine...This is reasonable... Code:
#include<iostream.h> |
Re: Why this code is not working?
In base calss j is protected member. In case 1 you are trying to assign value for a protected member . so it failed.
Where as in case 2, you used 'this' means derived class object. When a derived class object is created internally it will create base class object too . Since j is protected it is accessible by the derived class.. So you can assign the value. Where as in case 1 Base b is a different object, so you can't access the protected variable. |
| All times are GMT +5.5. The time now is 11:56. |