My intention is to call this function many times like so from inside *this object:Code:namespace algo { template<typename _Iterator, typename _Function, typename _Base> _Function for_each(_Iterator a, _Iterator z, _Function t, _Base base) { for (;a != z; ++a) base.t(*a); return t; } };
Where add_if_not_zero is part of the same object *this is.Code:algo::for_each(something.begin(),something.end(),add_if_not_zero,*this);
Code:void clear_extra() { algo::for_each(something.begin(), something.end(), add_if_not_zero, *this); }Here's my error:Code:class Expression { public: std::vector<Something> something; void add_if_not_zero(const Term&); void clear_extra(); //... };
I'm not sure what's wrong. Any clues? Ideas to improve for_each?Code:expression.cpp: In member function `void Expression::clear_extra()': expression.cpp:15: assuming pointer to member `void Expression::add_if_not_zero(const Term&)' expression.cpp:15: (a pointer to member can only be formed with `& Expression::add_if_not_zero(const Term&)') expression.hpp: In function `_Function algo::for_each(_Iterator, _Iterator, _Function, _Base) [with _Iterator = __gnu_cxx::__normal_iterator<Term*, std::vector<Term, std::allocator<Term> > >, _Function = void (Expression::*)(const Term&), _Base = Expression]': expression.cpp:15: instantiated from here expression.hpp:619: no matching function for call to `Expression::t(Term&)' make: *** [expression.o] Error 1



LinkBack URL
About LinkBacks


