我正在尝试重载 operator<< 以在 MapType 中打印 string* 的向量(请参阅下面的 typedef),但不断出错。请帮忙。这是详细信息,我有以下课程:
typedef map<string, vector<string*> > MapType;
class Thesaurus{
public:
...
friend ostream& operator<<(ostream& ostrm, const Thesaurus& T);
private:
MapType M;
string DeRef(string* i);
...
};
在哪里
ostream& operator<<(ostream& ostrm, const Thesaurus& T)
{
for(MapType::const_iterator mItr = T.M.begin(); mItr!= T.M.end(); mItr++)
{
ostrm<< endl;
ostrm<< mItr->first<<"\t"; //print word
transform(mItr->second.begin(), mItr->second.end(), ostrm, &Thesaurus::DeRef); // print synonyms vector
}
return ostrm;
}
string Thesaurus::DeRef(string* i)
{
return *i;
}
在 operator<< 中使用 transform 会引发以下错误:
"error C2248:'std::basic_ios<_Elem,_Traits>::basic_ios':cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'"