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;
私は、類似しているが同じ質問ではなく、オプションとしてmutableを横断しました。私の質問は私が正しいことをしているか、そうすることに落とし穴があるかどうかです。事前にあなたの助けをありがとう。Map in Map Map.Clear()error
//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
Chrisに感謝します。私はコードをあまりにも長く見つめていて、イテレータを当然としていたと思います。 「可視状態」の意味がわかりません。私はとにかく変更可能なものに精通していない、ちょうど別のポストがconstだったものを解決するためにそれを使用して、ちょうど私のために働いたが、もちろん私はこの質問をした。 – Tyhja