Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Bind2nd & mem_fun


Автор: Vyacheslav 15.9.2005, 13:00
Не получается заставить работать следующий код. Есть идеи или это впринципе не возможно.

Код

struct TextContent 
{
/
public:
/...
    bool x_less( long max )  { return x < max; }
};
/...
vector<TextContent> pageContents; 
//...
pageContents.erase(remove_if(pageContents.begin(), pageContents.end(),
    bind2nd(mem_fun1(&TextContent::y_less),100)),pageContents.end() );


Цитата

c:\program files\microsoft visual studio\vc98\include\algorithm(50) : error C2664: '()' : cannot convert parameter 1 from 'struct AV_Parser::TextContent' to 'struct AV_Parser::TextContent *const & '
        Reason: cannot convert from 'struct AV_Parser::TextContent' to 'struct AV_Parser::TextContent *const '
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        c:\program files\microsoft visual studio\vc98\include\algorithm(299) : see reference to function template instantiation 'struct AV_Parser::TextContent *__cdecl std::find_if(struct AV_Parser::TextContent *,struct AV_Parser::TextContent *,clas
s std::binder2nd<class std::mem_fun1_t<bool,struct AV_Parser::TextContent,long> >)' being compiled


Автор: Mayk 15.9.2005, 14:16
memfun принимает указатель. А у тебя в векторе таковых нет:
Цитата

Reason: cannot convert from 'struct AV_Parser::TextContent' to 'struct AV_Parser::TextContent *const '
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


Код

    pageContents.erase(remove_if(pageContents.begin(), pageContents.end(),
        bind2nd(mem_fun1_ref(&TextContent::x_less),100)),pageContents.end());    

вот это вот компилируется из под bcc55, vs2003.

Автор: Vyacheslav 15.9.2005, 14:29
А в 6-ом. У меня в шестом не компилится ни mem_fun1_ref, ни mem_fun1

Автор: Mayk 15.9.2005, 14:55
Если заменить vector<TextContent> на vector<TextContent*> и оставить mem_fun1, что говорит?

Автор: Vyacheslav 15.9.2005, 15:15
Нормально транслируется

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)