I\'m trying to build a program whose source I downloaded from the internet. When I try to compile it, I get the error message
friend declaration specifying
As many have mentioned before, a struct
is the same as a class
, except that its members are public
by default. It can have private members.
I'm guessing here, but I think the idea behind making this a friend factory function is that it the designer of the library is reserving the right to initialize any private members added in the future.
To answer your questions:
mkLit
before the struct
is a problem because it returns a Lit
, and Lit
hasn't been defined yet (since it now appears below mkLit
).friend
declaration inside the struct
will work because the struct
has no private members -- for now. If you ever merge in a newer version of the original library that changes adds private members (or makes members private by default by changing the text struct
to class
), then it will stop working.(note: I pasted your code into http://godbolt.org and tried the various permutations, using different compilers)