类崩溃编译器中的 MSVC 2010 模板化映射

MSVC 2010 templated map in class crashing compiler

本文关键字:映射 2010 MSVC 崩溃 编译器      更新时间:2023-10-16

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

#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 test{
    public:
        template <typename T>
        class Map {
        public:
            std::map<std::string, T> stuff;
        };
    };

相反。