번역기를 직접 만들려고합니다. 그것은 대학 일입니다. 내 클래스에서 반복자가 필요합니다. 역자.C++의 반복자
class Translator
{
private:
map <string,Word> translator;
public:
class iterator
{
friend class Translator;
private:
map<string,Word>::iterator itm;
public:
iterator operator++();
pair <string,Word> &operator*();
bool operator==(const iterator &it)const;
};
};
과부하를 시도하고 있습니다. operator*()
;
이것은 코드입니다.
pair <string, Word>& Translator::iterator::operator*()
{
return (*itm);
}
에러 : 맵의
invalid initialization of reference of type ‘std::pair<std::basic_string<char>, Word>&’ from expression of type ‘std::pair<const std::basic_string<char>, Word>
BTW, 당신은'translator' 적은 일을 호출 할 수 있습니다 : 여기
은 내가 준 링크에서 예입니다. 코드에 대한 이야기 / 추론을 쉽게하기. ;) – Yakk