V
Vincent RICHOMME
Hi,
I still have problems with some class and their members.
I have two classes declared as :
typedef struct tagStructB
{
int iSizeB;
char* szTextB;
} StructB;
typedef struct tagStructA
{
int iSizeA;
char* szTextA;
StructB sStructB;
} StructA;
class B
{
public:
friend class A;
B(structB& refStructB) { m_refStructB = refStructB ;}
int GetSize() {return m_StructB.iSizeB;}
char* GetText() {return m_StructB.szTextB;}
protected:
structB& m_refStructB;
};
class A
{
public:
A();
int GetSize() {return m_StructA.iSizeA;}
char* GetText() {return m_StructA.szTextA;}
void Test() { int iTest = m_B.m_refStructB.iSizeB; } // IT WORKS
B& GetB() { return m_B; }
protected:
structA m_StructA;
B m_B;
};
So if I declare class A as a friend of B I CAN have direct access to
protected members of B.
Now if I derive a class from A like this:
class AProp: public A,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
int iTest = m_B.m_refStructB.iSizeB; // FAILS !!!!!!
}
IPropertyHost* GetPropPointer() { return this; }
};
in my GetProperties method, I always have the error message cannot
access protected member declared in class B.
I still have problems with some class and their members.
I have two classes declared as :
typedef struct tagStructB
{
int iSizeB;
char* szTextB;
} StructB;
typedef struct tagStructA
{
int iSizeA;
char* szTextA;
StructB sStructB;
} StructA;
class B
{
public:
friend class A;
B(structB& refStructB) { m_refStructB = refStructB ;}
int GetSize() {return m_StructB.iSizeB;}
char* GetText() {return m_StructB.szTextB;}
protected:
structB& m_refStructB;
};
class A
{
public:
A();
int GetSize() {return m_StructA.iSizeA;}
char* GetText() {return m_StructA.szTextA;}
void Test() { int iTest = m_B.m_refStructB.iSizeB; } // IT WORKS
B& GetB() { return m_B; }
protected:
structA m_StructA;
B m_B;
};
So if I declare class A as a friend of B I CAN have direct access to
protected members of B.
Now if I derive a class from A like this:
class AProp: public A,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
int iTest = m_B.m_refStructB.iSizeB; // FAILS !!!!!!
}
IPropertyHost* GetPropPointer() { return this; }
};
in my GetProperties method, I always have the error message cannot
access protected member declared in class B.