在名称空间中使用具有相同名称的类? [英] Using a class in a namespace with the same name?

查看:192
本文介绍了在名称空间中使用具有相同名称的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用DLL提供的API,其中包含类似这样的标头

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

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

是否有办法使用ALongNameToType :: ALongNameToType: :Foo,而不必每次键入ALongNameToType :: ALongNameToType?我尝试使用使用命名空间ALongNameToType 但在Visual Studio中有歧义的符号错误。更改命名空间名称或删除命名空间名称会导致链接器错误。

Is there a way to use ALongNameToType::ALongNameToType::Foo without having to type ALongNameToType::ALongNameToType each time? I tried using using namespace ALongNameToType but got ambiguous symbol errors in Visual Studio. Changing the namespace name or removing it gives me linker errors.

推荐答案

我不知道什么是模糊的,与其他Foo函数冲突,如下所示:

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();
}

这篇关于在名称空间中使用具有相同名称的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆