Jump to content
  • Advertisement
Sign in to follow this  

[C++] overloading std::find_if

This topic is 3685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I thought I was doing everything right, as I even copy-pasted the solutions from GD and modified them to my liking. Now it's still not working and I'm giving out my code for some fresh eyes to see.
#include <fstream>
#include <iostream>
#include <string>

#include <exception>
#include <algorithm>
#include <vector>

using namespace std;

	// Harspoolov algoritem
    struct bch_element_t {
        bch_element_t( const char c ) 
        : znak( c ), odmik( int() ) {}    
		bool operator()( const bch_element_t &rhs )
            return this->znak == rhs.znak;
        char znak;
        int odmik; 

int main()
        // declaration
        string c[3] = { "bla1", "bla2", "bla3" };
	vector<bch_element_t> bch[3];
        // i've push_back'd some elements..

        // and then did this (is this the correct usage?)
	if( find_if( bch.begin(), bch.end(), bch_element_t( c[j] ) ) == false )


but the compiler gives out this error: 76 H:\ARP\dn_n_fix.cpp no match for ` __gnu_cxx::__normal_iterator<bch_element_t*, std::vector<bch_element_t, 65 C:\Program Files\Dev-Cpp\include\objbase.h candidates are: BOOL operator==(const GUID&, const GUID&) thanks! PS: I'd also like to note, that I've first tried overloading std::find (as it doesn't matter which one I use), and the same error occured.

Share this post

Link to post
Share on other sites
find_if does not return a boolean (so you get an error on the '== false' comparison). It returns an iterator within the range that satisfies the predicate (if any) or the past-the-end iterator for the range (if none). So, your comparison would be '== bch.end()' instead.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!