Rootcint+namespace error

Dear all, this might as well be a C++ error but here it goes: I have the following concept:

namespace name {

namespace space1 {

class Friend {

};

};

};

namespace name {

namespace space2 {

MyClass {

friend ::name::space1::Friend;

};

};

};

For some reason I get Error: class, struct, union or type name::space1 not defined (in the line with the friend declaration) in rootcint. I think I am missing something simple. Any ideas? Should I #include the Friend.h file in any case? I would like to avoid this. Thanks,

filimon

Hi,
your example works for me (after adding “class” in front of “MyClass”).
Axel.

OK, after re-reading the between-the-lines part of your posting: yes you should #include Friend.h, or properly forward declare it. A friend decl is NOT a fwd decl.

Axel.

I tried fwd declarations

  1. class name::space1::Friend;,
  2. using name::space1::Friend;
    class name::space1::Friend;

with/out leading ::, in and out of the name::space2 scope and the MyClass scope and I still get the same error. Could you post the working example maybe? I really think I am missing sth simple. #including Friend.h is not really an option actually :frowning: Thanks,

filimon

[quote]I tried fwd declarations

  1. class name::space1::Friend;,
    [/quote]
    you cannot make “forward declaration” for qualified class-name.

If you cannot include “Friend.h” you have to manually declare class.
At least, you can use such forward declaration:

namespace name
{
   namespace space1
  {
     class Friend;
  }
}

class MyClass {
   friend class name::space1::Friend;
};

Thanks, this works as expected. I was under the wrong impression that name::space::ident and namespace name { namespace space { ident; } } are the same. Do you have any specific source on this information (e.g. a reference in the C++ standard or a book), refering to the conditions of friend declarations? I was not able to find anything on a quick look in the 1997 standard. Thanks,

filimon

[quote]Thanks, this works as expected. I was under the wrong impression that name::space::ident and namespace name { namespace space { ident; } } are the same. Do you have any specific source on this information (e.g. a reference in the C++ standard or a book), refering to the conditions of friend declarations? I was not able to find anything on a quick look in the 1997 standard. Thanks,
filimon
[/quote]

No, they are not the same. And your problem was not the friend declaration.
I guess you have to read the clause 3 - the part, describing name lookup, and, may be, about elaborated-type-specifiers.
If you have qualified name
name1::name2::name3 compiler should know, what ‘name1’ means (so, it should be declared and let’s say, it’s a namespace), after that, compiler will look up ‘name2’ in namespace ‘name1’ etc. - so you have to declare these entities before you can use such qualified name (it’s very simplified, incomplete and inaccurate description).
But… even if you have declared them:

namespace A
{
namespace B
{
class C{};
}
}

you cannot write

class A::b::C; it’s an ill-formed construct, and, for example, comeau compiler will give you error like this:

and standard prohibits such declaration explicitly, read about elaborated-type-specifiers in the clause 3