O
olanglois
Hi,
I am not sure if I have found a compiler bug (I am using VC++.NET2003)
or if this is the correct behavior defined by the language but I am
sure someone can clear up my confusion. Suppose the following:
class Base
{
protected:
int x;
};
class Derived : public Base
{
public:
void A( const Derived &d )
{ x = d.x; // Ok }
void B( const Base &b )
{ x = b.x; //Error: cannot access protected member declared in
class 'Base' }
};
What is the problem with B()? What should I change in Derived to fix
the problem? The best thing I came up is by modifying Base like this:
class Base
{
protected:
void SetX(const Base &b) { x = b.x; }
int x;
};
and call SetX from B().
Thanks,
Olivier Langlois
http://www3.sympatico.ca/olanglois
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
I am not sure if I have found a compiler bug (I am using VC++.NET2003)
or if this is the correct behavior defined by the language but I am
sure someone can clear up my confusion. Suppose the following:
class Base
{
protected:
int x;
};
class Derived : public Base
{
public:
void A( const Derived &d )
{ x = d.x; // Ok }
void B( const Base &b )
{ x = b.x; //Error: cannot access protected member declared in
class 'Base' }
};
What is the problem with B()? What should I change in Derived to fix
the problem? The best thing I came up is by modifying Base like this:
class Base
{
protected:
void SetX(const Base &b) { x = b.x; }
int x;
};
and call SetX from B().
Thanks,
Olivier Langlois
http://www3.sympatico.ca/olanglois
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]