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

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;
}

 

posted @ 2021-08-26 10:20  冰糖葫芦很乖  阅读(4375)  评论(0编辑  收藏  举报