void destroy()
{
AList::const_iterator a;
for(a = AList.begin(); a != AList.end();)
{
if(!a->second.BList.empty())
a->second.BList.clear();//will give error if not mutable
}
}
typedef std::map<unsigned int,int> bmap;
typedef std::map<unsigned int,someStruct> Alist;
typedef struct someStruct
{
float x,y,z;
bmap BList; //needs to be mutable for Blist.clear() above.
//mutable bmap BList; //<---like this
} someStruct;
Я случайно наткнулся на мутабельный вариант в похожем, но не в том же вопросе.Мой вопрос в том, правильно ли я поступаю или есть ли какие-либо подводные камни в этом?Заранее благодарю за помощь.
//error given: (if otherwise not mutable)
// error: passing 'const AList' as 'this' argument of 'void std::map<_Key, _Tp, _Compare, _Alloc>::clear() [with _Key = unsigned int, _Tp = int, _Compare = std::less<unsigned int>, _Alloc = std::allocator<std::pair<const unsigned int, int> >]' discards qualifiers