ページ 11

入れ子のsetに挿入

Posted: 2013年1月16日(水) 17:37
by set
VIsual Stdio 2012 で C++ です
入れ子のセットに対してイテレータ i を作り、イテレータが指す子のsetにsaとsbを挿入したく、
i->insert(sa)と書いたのですが
    error C2663: 'std::set<_Kty>::insert' : 4 オーバーロードに 'this' ポインターのための必要な定義がされていません。
とコンパイルエラーが出ます。なぜですか?
i->find(sa)やi->end()ではエラーが出ないのですが・・・
よろしくお願いします。


コード:

#include<iostream>
#include<set>
#include<string>

set< set<string> > setset;

void findInsert(string sa, string sb){
	for(set< set<string> >::iterator i=setset.begin(); i!=setset.end(); ++i){
		if(i->find(sa)!=i->end() || i->find(sb)!=i->end(){
			i->insert(sa);
			i->insert(sb);
		}
	}
}

Re: 入れ子のsetに挿入

Posted: 2013年1月16日(水) 18:04
by h2so5
std::setではイテレータによる走査中に内容を変更することができません。

参考URL:
http://stackoverflow.com/questions/2523 ... ual-studio

Re: 入れ子のsetに挿入

Posted: 2013年1月17日(木) 12:12
by set
ありがとうございました

Re: 入れ子のsetに挿入

Posted: 2013年1月17日(木) 12:26
by みけCAT
解決でしたら、解決チェックをお願いします。