#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;
}
What is wrong with this? Without explicit instantiation it breaks at
data[3] = 4;Explicit instantiation solves the problem but the program breaks after
std::cout << data.size() << std::endl;what means that the static class template memeber
data
was instantiated.