"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:4y*******************@newsread1.mlpsca01.us.t o.verio.net...
John A. Byerly wrote: I have a couple of classes that are causing compile errors. I hope
someone can shed some light as to why.
class A
{
public:
A(X* pX) : m_pX(pX) {};
protected:
X* m_pX;
};
class SubA : public A
{
public:
SubA(A& a) : A(a.m_pX) {};
};
When I compile this, I get an error stating that I can't access
protected member A::m_pX.
Would someone be so kind as to 'splain this to me?
You can't access protected members of a class different from the one from
which you try to access the protected members.
Thanks!
Now I have a followup question :-)
I am trying to make a storable version of a class. For instance,
class A
{
public:
A(double value) {};
protected:
A() : m_value(0.0) {};
double m_value;
};
I want to make a storable version of A, so I thought I would write
class StorableA
{
public:
StorableA() {};
Load(Storage& s) {???};
Store(Storage& s) {???};
};
I want to be able to pull values from storage and populate the object. That
should be easy: just create a StorableA and populate it. Okay, now, given
an instance of A, I want to be able to store it. One way of doing this
would be to create a sort of copy constructor for StorableA.
class StorableA
{
public:
StorableA() {};
StorableA(A a) : m_value(a.m_value) {};
Load(Storage& s);
Store(Storage& s);
};
StorableA::Store(Storage& s)
{
s.Store(m_value);
}
This won't work because I can't access protected members of A.
Am I out of luck?
JAB
--
--------------------------------------------------------
John A. Byerly
Engineered Software Solutions, Ltd.
http://www.ess-quality.com