Problem find_if with bind2nd

Nov 26, 2012 at 7:38pm
Hi!
I have the next code:

Engine.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

std::list<GameScreen*>Engine::gamescreens;

void Engine::PushGameScreen(GameScreen *n_gs)
{
    if (n_gs->getEngine() !=  NULL)
    {
        ExitOnGLError("ERROR: This Gamescreen exist in the stack of other Engine");
    }


    // Miramos si hay un GameScreen igual en la pila de GameScreens
    list<GameScreen*>::iterator result = find_if(
                                          gamescreens.begin(),
                                          gamescreens.end(),
                                          bind2nd<CompareGS>(CompareGS(),n_gs)//LINE 223
                                          );
    // Si es unico este GameScreen enviado, lo añadimos a la pila. Sino, avisamos de que ya existe
    if(result == gamescreens.end())
    {
        n_gs->setEngine(this);
        n_gs->LoadGameScreen();
        gamescreens.push_back(n_gs);
    }
    else
    {
        cout<<"INFO: This Gamescreen has already been loaded "<<endl;
    }
}


GameScreen.hpp

1
2
3
4
5
6
7
struct CompareGS : public std::binary_function < GameScreen, GameScreen, bool>
        {
            bool operator() (const GameScreen& gs1, const GameScreen value) const
            {
                return (gs1 == value);
            }
        };


And I have the next log:

c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/backward/binders.h: In function 'std::binder2nd<_Operation> std::bind2nd(const _Operation&, const _Tp&) [with _Operation = CompareGS, _Tp = GameScreen*]':
C:\Users\Héctor\Documents\Visual Studio 2010\Projects\GekkoEngine\src\Framework\Engine.cpp:223: instantiated from here
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/backward/binders.h:162: error: no matching function for call to 'GameScreen::GameScreen(GameScreen* const&)'
C:\Users\Héctor\Documents\Visual Studio 2010\Projects\GekkoEngine\src\Framework\../../include/../include/GameScreen.hpp:20: note: candidates are: GameScreen::GameScreen(std::string)
C:\Users\Héctor\Documents\Visual Studio 2010\Projects\GekkoEngine\src\Framework\../../include/../include/GameScreen.hpp:17: note: GameScreen::GameScreen(const GameScreen&)
In file included from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/algorithm:62,
from C:\Users\Héctor\Documents\Visual Studio 2010\Projects\GekkoEngine\src\Framework\../../include/Engine.hpp:6,
from C:\Users\Héctor\Documents\Visual Studio 2010\Projects\GekkoEngine\src\Framework\Engine.cpp:1:
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h: In function '_InputIterator std::__find_if(_InputIterator, _InputIterator, _Predicate, std::input_iterator_tag) [with _InputIterator = std::_List_iterator<GameScreen*>, _Predicate = std::binder2nd<CompareGS>]':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:4248: instantiated from '_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = std::_List_iterator<GameScreen*>, _Predicate = std::binder2nd<CompareGS>]'
C:\Users\Héctor\Documents\Visual Studio 2010\Projects\GekkoEngine\src\Framework\Engine.cpp:224: instantiated from here
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:158: error: no match for call to '(std::binder2nd<CompareGS>) (GameScreen*&)'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/backward/binders.h:146: note: candidates are: typename _Operation::result_type std::binder2nd<_Operation>::operator()(const typename _Operation::first_argument_type&) const [with _Operation = CompareGS]
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/backward/binders.h:152: note: typename _Operation::result_type std::binder2nd<_Operation>::operator()(typename _Operation::first_argument_type&) const [with _Operation = CompareGS]

When I compile, CodeBlocks open two files, binders.h and stl_algo.h.

Does anyone know why this happens?
Last edited on Nov 26, 2012 at 7:41pm
Nov 26, 2012 at 7:50pm
Your list holds GameScreen pointers, so your binary function needs to have both it's arguments as GameScreen pointers.
Nov 26, 2012 at 11:36pm
Ok. thanks. that is the problem.
Topic archived. No new replies allowed.