c++ - Visual Studio 2012 中的奇怪错误

标签 c++ visual-studio templates visual-studio-2012

为什么这段代码可以在 Visual Studio 2012 上编译并运行?这只是一个错误还是我遗漏了一些东西

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

最佳答案

听起来你的编译器正在将 SS 解释为注入(inject)的类名;在这种情况下,它是一种类型,因此声明是有效的。

但是,名称查找规则表明它应该被解释为构造函数,而不是类,因此您的编译器是错误的。其他人拒绝代码:http://ideone.com/7fJ1VM

有效的类型名称可以是类型别名DD,或者使用注入(inject)类名class DD::SS的详细类型说明符。

关于c++ - Visual Studio 2012 中的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27524776/

相关文章:

C++ 模板函数返回基于模板参数的类型

c++ - 通过属性 getter 访问 std::map 返回垃圾值

c++ - dip::EuclideanSkeleton不起作用(未处理的异常)

visual-studio - 使用 Web 应用程序创建数据库时 Azure NoRegisteredProviderFound

c++ - Qt/C++ 将通用对象序列化为 QSettings

c++ - 如何匹配模板类中的模板友元函数

c++ - 如何找到 -lm lib 并将其包含在 CMake 中?

c++ - 这个 C++ 列表有什么问题?

c# - 我们是否能够从应用程序在 Linux Ubuntu for windows 中安装 Microsoft Visual Studio(不是 Visual Studio 代码)?

c# - 确认消息框