#include <map>
#include <iostream>
template <typename T>
class A
{
static std::map<int, int> data;
public:
A()
{
std::cout << data.size() << std::endl;
data[3] = 4;
}
};
template <typename T>
std::map<int, int> A<T>::data;
//std::map<int, int> A<char>::data;
A<char> a;
int main()
{
return 0;
}
Was ist falsch daran? Ohne explizite Instanziierung bricht es um C++ - Vorlage statische Element Instanziierung
data[3] = 4;. Explizite Instanziierung löst das Problem, aber das Programm bricht nach
std::cout << data.size() << std::endl;ab, was bedeutet, dass der statische Klassenschablonenmember
data
instanziiert wurde.
Welcher Compiler? Ich glaube nicht, dass das deine Schuld ist. – Potatoswatter
Dies wird mit VS2010 berechnet. – linuxuser27
Ich benutze vs2008 und es kompiliert in der Tat, aber das Programm bricht bei Zeilendaten [3] = 4 – mrs