【问题标题】:MSVC 2010 templated map in class crashing compiler类崩溃编译器中的 MSVC 2010 模板化映射
【发布时间】:2012-04-23 17:36:20
【问题描述】:

为什么下面的代码会使编译器崩溃?

#include <iostream>
#include <string>
#include <map>

class test{
public:
    template <typename T>
    std::map<std::string, T> stuff;
};

int main(int argc, char* argv[])
{
    test peanuts;
    return 0;
}

是编译器出了问题还是什么?

【问题讨论】:

    标签: c++ class templates visual-c++ map


    【解决方案1】:

    你试图有一个模板变量,你只能有类模板或函数模板。如果它使编译器崩溃,那么 that 是一个错误,但它不是有效的 C++。你可以做类似的事情

        class test{
        public:
            template <typename T>
            class Map {
            public:
                std::map<std::string, T> stuff;
            };
        };
    

    改为。

    【讨论】:

      猜你喜欢
      • 2012-09-06
      • 2018-06-22
      • 1970-01-01
      • 2021-12-19
      • 2012-07-10
      • 1970-01-01
      • 2018-12-27
      • 2012-09-25
      • 1970-01-01
      相关资源
      最近更新 更多