简体   繁体   English

Visual Studio 2012中的奇怪错误

[英]weird bug in visual studio 2012

why does this code compiles and run on visual studio 2012? 为什么此代码可以在Visual Studio 2012上编译并运行? is this just a bug or i missing something 这是一个错误还是我错过了一些东西

namespace SSSS
    {
        namespace SSS
        {
            template <class T>
            class SS
            {
            public:
                typedef T ValueType;
                SS(){std::cout<<T();}
                SS(T t) { std::cout<<t;}
            };

            typedef SS<double> DD;
        }
    }
    int main()
    {
        SSSS::SSS::DD::SS d;
    }

It sounds like your compiler is interpreting SS as the injected class name; 听起来您的编译器正在将SS解释为注入的类名; in which case, it is a type, so the declaration is valid. 在这种情况下,它是一种类型,因此声明有效。

However, the name lookup rules say that it should instead be interpreted as the constructor, not the class, so your compiler is wrong. 但是,名称查找规则说应该将其解释为构造函数,而不是类,因此您的编译器是错误的。 Others reject the code: http://ideone.com/7fJ1VM 其他人则拒绝该代码: http : //ideone.com/7fJ1VM

Valid type names would be the type alias DD , or an elaborated type specifier using the injected class name, class DD::SS . 有效的类型名称将是类型别名DD ,或者是使用注入的类名称class DD::SS的详尽的类型说明符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM