-1

I'm trying to traverse through a vector of "Stimulus" class objects. And if the properties of the object match the criteria, I want that Stimulus object returned.

std::vector<Stimulus> BS_stimulus_list;

bool StimulusCollection::isNextPoint(Stimulus it){
if(it.GetPointDeg()=="(Some json value)" & it.GetEye()==currentEye){
    return true;
}
else{
    return false;
}

void StimulusCollection::NextBSStimulus(char e){
currentEye = e;
if (currentEye=='L'){
    vector<Stimulus>::iterator idx = find_if(BS_stimulus_list.begin(), BS_stimulus_list.end(),isNextPoint);
}

The code above gives me a compile error : must use '.' or '->' to call pointer-to-member function in..... What am I doing wrong? Or what should I do differently to avoid this altogether?

ni5arg
  • 13
  • 2

2 Answers2

1

Assuming that isNextPoint is marked static, you need to explicitly qualify it:

find_if(BS_stimulus_list.begin(), 
        BS_stimulus_list.end(), 
        StimulusCollection::isNextPoint)

If it's not static you can use a lambda expression in order to bind the invocation of isNextPoint to a particular instance of StimulusCollection.

Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
1

you have to specify the instance, either by using a lambda (see below) or std::bind

void StimulusCollection::NextBSStimulus(char e) {
    currentEye = e;
    if (currentEye=='L'){
        vector<Stimulus>::iterator idx = find_if(
            BS_stimulus_list.begin(), 
            BS_stimulus_list.end(),
            [this](const auto& stimulus) { return isNextPoint(stimulus); });
    }
}

(for C++14, change const auto& to const Stimulus& for older versions)

dan
  • 303
  • 1
  • 3
  • Thanks, this works with a little modification. [this](const auto& stimulus) { return isNextPoint(stimulus); }); is changed to [this](const Stimulus& stimulus) { return isNextPoint(stimulus); }); – ni5arg Sep 05 '18 at 15:08