Using a class in a namespace with the same name?

前端 未结 4 981
耶瑟儿~
耶瑟儿~ 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:48

    I don't know what's ambiguous, but you can avoid all conflicts with other Foo functions like this:

    namespace ALongNameToType {
        struct ALongNameToType {
            static void Foo();   
        };
    }
    
    typedef ALongNameToType::ALongNameToType Shortname;
    
    int main() {
        Shortname::Foo();
    }
    

提交回复
热议问题