2

次のコードでコンパイラがクラッシュするのはなぜですか?

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

コンパイラにバグがありますか?

4

1 に答える 1

1

テンプレート化された変数を使用しようとしています。クラス テンプレートまたは関数テンプレートのみを使用できます。コンパイラがクラッシュしている場合、それバグですが、有効な C++ ではありません。次のようなことができます

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

代わりは。

于 2012-04-11T12:11:43.073 に答える