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