Wednesday, 7 August 2013

Is it safe to access Base protected member this way?

Is it safe to access Base protected member this way?

I have two class:
class base
{
protected:
int x;
}
class der: public base
{
void Acc(base& b)
{
b.*(&der::x) = 5;
}
}
Is it safe to access a base protected member this way (&der::x) ? I'm
worried that it could point to a wrong variable.
Thanks for reading.

No comments:

Post a Comment