views:

289

answers:

3

Hello, all :)

I've got a scenario like the following:

class criterion 
{
// stuff about criteria...
};
namespace hex {

     class criterion : public criterion //does not compile
     {                                  //This should inherit from the
     //A hex specific criterion         //criterion class in the global namespace
     };

};

My question is -- how does one inherit from a class in a namspace which is the parent of another namespace?

Billy3

+3  A: 

Start with "::"

For example

class criterion : public ::criterion {};
stribika
+3  A: 

You need to specify the namespace, in this case the global one:

 class criterion : public ::criterion

Note that c++ doesn't specify any means of navigating namespaces as if they were a tree. For example, you can't specify the the "parent" namespace using ".." or any other shorthand - you have to use its name.

anon
A: 

This compiles for me, basically just explicitly show in what namespace the parent class is:

class A
{};
namespace B {
    class A : public ::A
    {};
    namespace C {
     class A : public B::A
     {};
    }
};
DeusAduro