小编eAi*_*eAi的帖子

带有模板化函数和'using namespace'的VS2008(+?)编译器错误

我发现的一些代码(下)这个奇怪的情况下,Visual Studio 2008的下无法编译,并产生一个"错误C2872:'模糊’:不明确的符号"第12行.

删除namespace RequiredNamespace最后一行的使用可以修复错误,但是我希望放在using namespace文件末尾应该没有效果.这也依赖于AnotherFunction作为一个模板函数,所以我希望编译器产生错误的范围模板的功能,或者不复位这样做之前所使用的命名空间的列表.

相同的代码在GCC下编译.

这两种编译器似乎生成的代码TemplatedFunctionusing namespace Namespace的定义,至少据我可以通过引入错误,看着他们输出的顺序告诉.

namespace Ambiguity
{
    class cSomeClass
    {
    };

    template<class T>
    void TemplatedFunction(T a)
    {
        // this is where the error occurs, the compiler thinks Ambiguity
        // might refer to the class in RequiredNamespace below
        Ambiguity::cSomeClass(); 
    }
}

namespace RequiredNamespace 
{
    // without a namespace around this class, the Ambiguity class 
    // and namespace collide
    class Ambiguity
    {
    };
}

int main() …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction templates namespaces

5
推荐指数
2
解决办法
203
查看次数