mre*_*elt 0 c++ types stl list map
在当前的项目中,我正在编写C++,我经常使用STL类映射,设置和列表.现在我感兴趣的是有没有办法通过使用内部数据类型来清理一些代码.例如:
std::map<uint64_t, std::list<int32_t> > mymap;
// add something to the map
for (std::map<uint64_t, std::list<int32_t> >::const_iterator it = mymap.begin (); it != mymap.end (); it++) {
// iterate here
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我可以替换,std::map<uint64_t, std::list<int32_t> >::const_iterator例如mymap.const_iterator,但不编译.在这里引用g ++:
error: invalid use of ‘std::map<long long unsigned int, std::list<int, std::allocator<int> >, std::less<long long unsigned int>, std::allocator<std::pair<const long long unsigned int, std::list<int, std::allocator<int> > > > >::const_iterator’
Run Code Online (Sandbox Code Playgroud)
有关如何做到这一点的任何想法?还是不可能?
typedef std::map<uint64_t, std::list<int32_t> > mymaptype;
mymaptype mymap;
for (mymaptype::const_iterator ...
Run Code Online (Sandbox Code Playgroud)