Re: Can't access private struct of a class from a friend class
jpitt42@gmail.com schrieb:
I get "error: `struct Addr::ADDR_T' is private" from the following
code when trying to access Addr::ADDR_T from MsgFactory, which is a
friend. I have verified that MsgFactory can access private member
data of Addr with no problem, but it's unable to access the struct for
some reason.
I strongly recommend that you always try to post a complete
and/or self-explaining snippet to demonstrate your problem.
class Addr
{
friend class MsgFactory;
private:
typedef struct
{
int addr;
} ADDR_T;
...
};
Where is the below accessed getRefAddrStruct() function declared?
I assumed the following scenario:
class Addr
{
friend class MsgFactory;
private:
typedef struct
{
int addr;
} ADDR_T;
const ADDR_T& getRefAddrStruct() const {
....
}
};
Have you considered that getRefAddrStruct() might
be written const-incorrect? You *need* the const
qualifier!
class MsgFactory
{
public:
boolean
send(void** ptrPtrMsg, const Addr& refDestAddr);
What is "boolean"? I assume, that it is a typedef equivalent
to bool.
boolean
MsgFactory::send(void** ptrPtrMsg, const Addr& refDestAddr)
{
// The following line causes "error: `struct Addr::ADDR_T' is private"
printf("Hidden address = %d",
refDestAddr.getRefAddrStruct().addr);
....
};
I have - of course - the same problem with "boolean" here.
But under the premisse that my assumed code applies
here, I see no problem with your code and it should compile.
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]