I am writing an assignment, in WordMultiSet::print(), I want to use for_each( myvc.cbegin(), myvc.cend(), bind1st(mem_fun(&WordMultiSet::printelement), this)) to pass the contents in vector<string> myvc to member function WordMultiSet::printelement(const string& ws)
but I just can not do it ,can someone help me, this is so hard for me to understand, I don't know what to do next:)
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
void WordMultiSet::print() const // print the contents of the container to the standard out put stream, cout
{
vector<string> myvc(wordset.size());
//Copy the elements in the range of wordset to the range beginning at myvc,
//except consecutive duplicates (elements that compare equal to the element preceding).
auto it = unique_copy (wordset.begin(),wordset.end(),myvc.begin()); //
myvc.resize(distance(myvc.begin(), it)); //resize the vector
for_each( myvc.cbegin(), myvc.cend(), bind1st(mem_fun(&WordMultiSet::printelement), this));
}
void WordMultiSet::printelement(const string& ws) const
{
int count = lookup(ws.c_str());
cout<<count<<" : "<<ws<<endl;
}
|
this is the error I got:
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xfunctional(286): error C2535: 'void std::binder1st<_Fn2>::operator ()(const std::basic_string<_Elem,_Traits,_Alloc> &) const' : member function already defined or declared
1> with
1> [
1> _Fn2=std::const_mem_fun1_t<void,WordMultiSet,const std::string &>,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xfunctional(280) : see declaration of 'std::binder1st<_Fn2>::operator ()'
1> with
1> [
1> _Fn2=std::const_mem_fun1_t<void,WordMultiSet,const std::string &>
1> ]
1> f:\cpp\comp5421_assignment5\wordmultiset.cpp(56) : see reference to class template instantiation 'std::binder1st<_Fn2>' being compiled
1> with
1> [
1> _Fn2=std::const_mem_fun1_t<void,WordMultiSet,const std::string &>
1> ]