namespaces confusion

Hello

In one header file i have a namespace IMAGE with a class in it.
1
2
namespace IMAGE { 
class someThing {}; }


And in another header file i have have a nested namespace within IMAGE and some functions defined there
1
2
3
4
5
namespace IMAGE {
   namespace PROCESS {
     void func1();
}
}

Now i want to declare all the functions in namespace PROCESS as friends to the class someThing inside the namespace IMAGE.

Im getting compilation errors but i cant understand if there is something wrong with my code or the order of compilation.(because the first header includes the second one and the second includes the first one.)

Inside class someThing i tried something like that.
friend void IMAGE::PROCESS::func1();
friend void PROCESS::func1();

I even declared in the first header an empty namespace PROCESS but still nothing.

Any ideas???

Thanks
Include the second header in the first header.
I tried just to include the header to each other but it didnt work.Giving errors that class 1 in namespace A could not see namespace B and func in B.

I did it this way but i dont know if it is the recommended way to do it.Just defined an empty class in header2 and the func definition in header1

header1.h
1
2
3
4
5
6
7
8
9
10
11
12
namespace A{
        class Image;

           namespace B{
                  void func( A::Image& );
           }

        class Image{
                members...
                friend void B::func( Image& );
        };
}


header2.h
1
2
3
4
5
6
namespace A {
         class Image;
         namespace B{
              void func( A::Image& );
         }
}


this way works fine .i just include the first header in the second cpp.
But i dont know if i just have one .h and two .cpp if it is to write the same definitions twice.
What do you think?









Don't make both header include each other. Only include header2.h in header1.h.

header1.h
1
2
3
4
5
6
7
8
#include "header2.h"

namespace A{
        class Image{
                members...
                friend void B::func( Image& );
        };
}


Leave header2.h as you have it.
Last edited on
Actually it doesnt work if i just include header2 in header1.
Giving errors that namespace B and even functions defined in namespace B are not defined.Thats why i had to redefine namespace B and the functions in it in header 1 .
Topic archived. No new replies allowed.