类中静态容器对象如何初始化
#include#include#includeusing namespace std;class CTest{private:static set m_set;static map m_map;public:static void print(){for(set::iterator
·
#include <set>
#include <map>
#include <iostream>
using namespace std;
class CTest
{
private:
static set<int> m_set;
static map<int,char*> m_map;
public:
static void print()
{
for(set<int>::iterator iter = m_set.begin(); iter != m_set.end(); ++iter)
cout << *iter << endl;
cout<<endl;
for(map<int,char*>::iterator iter = m_map.begin(); iter!=m_map.end(); ++iter)
cout << iter->first <<"\t"<< iter->second << endl;
}
};
set<int> initial_set()
{
set<int> tmp;
for(int i = 0; i < 10; ++i)
{
tmp.insert(i);
}
return tmp;
}
map<int,char*> initial_map()
{
map<int,char*> tmp;
for(int i = 0; i < 10; ++i)
{
tmp.insert(make_pair(i,(char*)"hello"));
}
return tmp;
}
set<int> CTest::m_set(initial_set()); //
map<int,char*> CTest::m_map(initial_map()); //
int _tmain(int argc, _TCHAR* argv[])
{
CTest obj;
obj.print();
return 0;
}
更多推荐
已为社区贡献2条内容
所有评论(0)