I ran into an error yesterday and, while it\'s easy to get around, I wanted to make sure that I\'m understanding C++ right.
I have a base class with a protected memb
protected
members can be accessed:
this
pointerTo solve your case you can use one of last two options.
Accept Derived in Derived::DoSomething or declare Derived friend
to Base:
class Derived;
class Base
{
friend class Derived;
protected:
int b;
public:
void DoSomething(const Base& that)
{
b+=that.b;
}
};
class Derived : public Base
{
protected:
int d;
public:
void DoSomething(const Base& that)
{
b+=that.b;
d=0;
}
};
You may also consider public getters in some cases.