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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM