Псевдоним пространства имен C ++ во всей области класса

I expected to be able to use a namespace alias in a class declaration but get a compiler syntax error.

struct MyClass
{
    namespace abc = a_big_namespace;
    void fn() {
        abc::test();
    }
};

The only way I can get it to work is to put the alias in every function.

void fn() {
    namespace abc = a_big_namespace;
    abc::test();
}

Additionally I would like to be able to use the alias for function parameters. I haven't found a work-around for that.

void fn(abc::testType tt) {
    abc::test(tt);
}

Is there a way to do what I want?

EDIT: my solution

I found that I didn't need unnamed namespace for my particular problem and can simply do this:

namespace myspace
{
    namespace abc = a_big_namespace;

    struct MyClass
    {
       void fn(abc::testType tt) {
          abc::test(tt);
       }
    };
}

To switch to the other library, which is what my alias namespace refers to I just change the alias. This method even allows me to have the same class in a single file twice, each time refering to a different library. Thanks for all your help.

32
задан Ant 20 May 2011 в 11:38
поделиться