次のコードスニペット。静的メンバー変数マップは、デフォルトのコンストラクターを使用して初期化されます。
#include <iostream>
#include <map>
using namespace std;
class A
{
static map<int, int> m_map; //static member variable
public:
void PrintSize()
{
//accessing it
//so that the map gets into the executable
cout < m_map.size() << endl;
}
};
// Initializing the static map member variable
map<int, int> A::m_map = map<int, int>();
int main()
{
A a;
cout << sizeof(a) << endl;
a.PrintSize();
return 0;
}
プログラムは正常に実行されます。私の質問は、保存されている静的マップを初期化するために形成される一時変数はどこにあるのかということです。