- Because your member is not a pointer or reference, the compiler needs to know the size of
G
. You can't use a forward declaration. - As noted in the comment, you need to qualify
G
with the namespace.
Here is code which compiles for me:
namespace GSpace
{
class G
{
};
}
class M
{
public:
friend class GSpace::G;
private:
GSpace::G gClassMember;
};
int main() {return 0;}