error: `int Base::j' is protected
error: within this context
Code:
#include<iostream.h>
class Base
{
public:
Base() { i=10; j=20;}
int i;
protected:
int j;
};
class Derived : public Base
{
public:
Derived() { k=30;}
int k;
void fun(Base);
};
void Derived :: fun(Base b)
{
b.i=100;
b.j=200; //Problem is here...
}
int main()
{
Base Bobj;
Derived Dobj;
Dobj.fun(Bobj);
return 0;
}
CASE 2: This code works fine...This is reasonable...
Code:
#include<iostream.h>
class Base
{
public:
Base() { i=10; j=20;}
int i;
protected:
int j;
};
class Derived : public Base
{
public:
Derived() { k=30;}
int k;
void fun(Base);
};
void Derived :: fun(Base b)
{
b.i=100;
this->j =200;
//b.j=200;
}
int main()
{
Base Bobj;
Derived Dobj;
Dobj.fun(Bobj);
return 0;
}
