Hi,
I've got construction of namespaces like this:

namespace one
{
     namespace two
    {
         class SomeClass{...};
    }
}

and when I try to use this class (without fully qualified name) in another file (also with nested namespaces) I'm getting errors. It doesn't even help if I place declaration of using this namespace in the file in which I'm intend to use this class. The only way I found is to use fully qalified names if there is more than one level of namespaces, but I hope that there is solution to this. Looking forward to your replays. Thank you.

Recommended Answers

All 3 Replies

Hmm. Hard to say without seeing code, really. You could always using namespace namespaceOne::namespaceTwo; if you wanted to hide the thing.

Please post the smallest compilable example of your problem. "I'm getting errors" doesn't really let us know what is going on.

My guess is you need to put "typename" in front of your nested qualifier:

typename namespaceOne::namespaceTwo::YourClass A;
//instead of
//namespaceOne::namespaceTwo::YourClass A;

The later is ambiguous - the compiler tries to call a function, so you have to make it clear that you, instead, want to declare a variable of that type.

Dave

Thank you for all your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.