[ACCEPTED]-Accessing Parent Namespace in C++-namespaces

Accepted answer
Score: 18

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

 class criterion : public ::criterion 

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

Score: 8

Start with "::"

For example

class criterion : public ::criterion {};

0

Score: 7

Simplified basic C++ namespace rules are:

  • You can access anything in parent namespace path without specifying namespace.
  • You can access anything in child namespace path by specifying only relative path.
  • Everything else requires full namespace specifications.

0

Score: 3

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

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

More Related questions