I do use #pragma once at the beginning of every header file.
I've changed my code in a few places. Now I've gotten to a situation like this:
file1.h:
file2:Code:namespace one { class class1 { int x; friend class class2; }; }
main.cpp:Code:#include "file1.h" class class2 { public: int y; class class2() { one::class1 obj; obj.x = 3; } };
And I get these errors in file2:Code:#include "file2.h" .... //in the main function: class2 obj;
Why does the friendship not work? well... I assume it expects the class to belong in the same namespace. But, isn't there a way to do it without putting class2 in a namespace?Code:error C2248: 'one::class1::x' : cannot access private member declared in class 'one::class1' IntelliSense: member "one::class1::x" (declared at line 6 of "d:\my projects\testslearn\testslearn\file1.h") is inaccessible
it seems that friend class ::class2; does not work, even if class2 is global.
It says:
Code:error C2039: 'class2' : is not a member of '`global namespace'' error C2248: 'one::class1::x' : cannot access private member declared in class 'one::class1'




Reply With Quote