Using a class in a namespace with the same name?

前端 未结 4 982
耶瑟儿~
耶瑟儿~ 2021-01-11 15:11

I have to use an API provided by a DLL with a header like this

namespace ALongNameToType {
    class ALongNameToType {
        static void Foo();   
    }
}
         


        
4条回答
  •  天涯浪人
    2021-01-11 15:40

    namespace myns = ALongNameToType;
    

    It seems that you can't alias a class scope like this:

    // second ALongNameToType is a class
    namespace myns = ALongNameToType::ALongNameToType;
    

    Maybe you could alias the function it self:

    namespace foo
    {
     class foo
     {
     public:
      static void fun()
      {
    
      }
     };
    }
    
    int main()
    {
     void (*myfunc)() = foo::foo::fun;
    
     myfunc();
    }
    

提交回复
热议问题