Reputation: 329
I am using class1 that contains a few governing variables and a vector of another class, class2. I would like to be able to flag various elements of the vector of class2 (using boolean variable 'delete_me') and then run the erase-remove idiom to eliminate those elements from the vector. I have found some examples of this on the web, but these are for simpler data structures than what I am using.
I am getting a type conversion error when I compile (using g++ v4.7.3).
Class2:
class Interval_structure {
//class uses default destructor
public:
float x1, x2, y1, y2;
float A;
float B;
float delta_x;
bool delete_me;
etc...
Class 1:
class CMR_Spline {
//class uses default destructor
public:
vector< Interval_structure > Interval;
int some_ints;
float some_floats;
bool IsMarkedToDelete( Interval_structure& o )
{
return o.delete_me;
}
void prune_Intervals() {
//intervals that have been slated for deletion are removed using the remove-erase idiom
Interval.erase( remove_if(Interval.begin(), Interval.end(), IsMarkedToDelete ), Interval.end() );
}
When I compile I get the following error, cited for the single line in the prune_Intervals routine using erase+remove_if:
error: cannot convert
CMR_Spline::IsMarkedToDelete' from type
bool (CMR_Spline::)(Interval_structure&) ' to type `bool (CMR_Spline::*)(Interval_structure&)'
I'm a little confused as to how I should write the IsMarkedToDelete function and prune_Intervals routine to correctly reflect the pointer that is used by remove-if to traverse the vector and evaluate IsMarkedToDelete.
How do I do this correctly using erase+remove_if, or if not that way please suggest an alternative approach. I am stumped and hindered by my limited programming experience. Thanks!
Upvotes: 2
Views: 390
Reputation: 477060
Make the function static:
static bool IsMarkedToDelete( Interval_structure& o )
{
return o.delete_me;
}
Upvotes: 2