Why does the following code crash the compiler?
#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;
}
Is there a bug in the compiler or what?
You are trying to have a templated variable, you can only have class templates or function templates. If it’s crashing the compiler, then that is a bug, but it is not valid C++. You can do something like
instead.