Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "b.h"
- namespace GLOBAL{
- class A{
- public:
- void doSomething(B);
- }
- }
- #include "a.h"
- using namespace GLOBAL;
- void A::doSomething(B b){
- b.use();
- }
- namespace GLOBAL{
- class B{
- public:
- friend void GLOBAL::A::doSomething(B);
- private:
- void use();
- }
- ‘GLOBAL::A’ has not been declared
- ‘void GLOBAL::B::use()’ is private
- namespace GLOBAL
- {
- class B;
- class A
- {
- public:
- void doSomething(B& b);
- };
- };
- namespace GLOBAL
- {
- class B
- {
- public:
- friend void GLOBAL::A::doSomething(B&);
- private:
- void use()
- {
- }
- };
- };
- void GLOBAL::A::doSomething(B& b)
- {
- b.use();
- }
- namespace GLOBAL
- {
- class B
- {
- public:
- friend class A;
- private:
- void use()
- {
- }
- };
- };
- namespace GLOBAL
- {
- class A
- {
- public:
- void doSomething(B b);
- };
- };
- void GLOBAL::A::doSomething(B b)
- {
- b.use();
- }
- friend class A;
- // #include "b.h" // remove this line it is not needed.
- namespace GLOBAL{
- class B; // Forward declare the class here.
- class A{
- public:
- void doSomething(B&); // Note: This should probably be a reference.
- // Change to doSomething(B&);
- }
- }
- // Add this line it is needed for the friend declaration.
- // To have a member as a friend we need the definition of 'A'
- #include "a.h"
- namespace GLOBAL{
- class B{
- public:
- friend void GLOBAL::A::doSomething(B&);
- private:
- void use();
- }
- #include "a.h"
- // Add this line to include the B definition so you know how to call use()
- #include "b.h"
- using namespace GLOBAL;
- void A::doSomething(B& b){ // b should be a reference otherwise you are copying it.
- b.use();
- }
Add Comment
Please, Sign In to add comment