首页 > 编程语言 > 详细

C++静态成员变量map如何初始化赋值

时间:2021-08-26 11:34:21      阅读:11      评论:0      收藏:0      [点我收藏+]
class a {
public:
    typedef std::map<int, int> urlMap;
    static urlMap mp;
    static urlMap CreateMap() {
        urlMap tmp_map = { {1, 1},{2, 2},{3, 3} };
        return tmp_map;
    }

};
a::urlMap a::mp = a::CreateMap();

int main()
{
    std::map<int, int>::iterator it = a::mp.begin();
    while (it != a::mp.end())
    {
        cout << it->first << " "<< it->second <<endl;
        it++;
    }
    return 0;
}

技术分享图片

 

C++静态成员变量map如何初始化赋值

原文:https://www.cnblogs.com/Galesaur-wcy/p/15188301.html

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