首页 > 编程语言 > 详细

How to initialize a static const map in c++?

时间:2015-08-11 14:01:39      阅读:287      评论:0      收藏:0      [点我收藏+]

#include <map>
using namespace std;
struct A{     
static map<int,int> create_map()         
{           
map<int,int> m;           
m[1] = 2;           
m[3] = 4;           
m[5] = 6;           
return m;         
}     
static const map<int,int> myMap;
}; 
const map<int,int> A:: myMap =  A::create_map(); 
int main() 
{ }

假设是vector。能够使用

#include <iostream>
#include <vector>
using namespace std;
class A

{
public:
static vector<int> v2;
void show()
{
for(vector<int>::iterator i = v2.begin() ; i!= v2.end(); i++)
{
cout<<*i<<endl;
}
}
};
vector<int> A::v2(2,6);

int main()
{
A obj;
obj.show();
return 0; 
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

How to initialize a static const map in c++?

原文:http://www.cnblogs.com/hrhguanli/p/4720759.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!