Orkun
Orkun

Reputation: 7238

anonymous namespace in c++ cannot access header

I have an enum in the header:

namespace somespace
{
    namespace internal
    {

        class SomeClass
        {
            public:

                typedef enum
                {
                    kNone = 0,
                    kKaka = 1,
                }SomeEnum;
        }
    }
}

In the cpp, we sometimes use an anonymous namespace with the helper functions.

#include <somespace/internal/SomeClass.h>

using somespace::internal;

namespace
{

    bool helpMe(SomeEnum& foo) //does not recognize the enum in the header
    {

    }
}

void SomeClass::memberMethod
{

}

But I cannot access the SomeEnum in the .cpp file. Why is that? How can I get around this without polluting the internal namespace for example?

Upvotes: 0

Views: 223

Answers (1)

NathanOliver
NathanOliver

Reputation: 180660

SomeEnum is scoped to the class name it is declared in. To use it you need SomeClass::SomeEnum. This assumes that SomeClass is accessible in the scope you have it. If not then you need somespace::internal::SomeClass::SomeEnum

Upvotes: 8

Related Questions