Rella
Rella

Reputation: 66945

Boost/std bind how to solve such errors? (binding function from one class to another class)

So I am triing to create a simple graph connecting one class to another...

#include "IGraphElement.h"

#include <boost/bind.hpp>

class  simpleRendererGraphElement : public IGraphElementBase, public simpleRendererLibAPI
{
public:
    IGraphElement<ExtendedCharPtr>* charGenerator;
    // we owerrite init
    void Init(IGraphElement<ExtendedCharPtr>* CharGenerator, int sleepTime)
    {
        charGenerator = CharGenerator;
        charGenerator->Add(boost::bind(&simpleRendererGraphElement::renderCastedData, this, std::placeholders::_1)); // line (**)

        SetSleepTime(sleepTime);
    }
    void renderCastedData(ExtendedCharPtr data) //  our event system receives functions declared like void FuncCharPtr(char*, int) ;
    { 
        DWCTU();
        renderChar(data.data);
    }

};

But it gives me C3083 and C2039 on line (**)... I use vs 2008 so I can not se std to bind... how to solve such issue?

BTW #include "IGraphElement.h" looks like

#include "IGraphElementBase.h"

// parts of c++0x std
#include <boost/bind.hpp> 
#include <boost/function.hpp>

#ifndef _IGraphElement_h_
#define _IGraphElement_h_

using namespace std ;
template <typename DataType >
class IGraphElement : public IGraphElementBase{

    typedef boost::function<void(DataType)>   Function;
    typedef std::vector<Function>      FunctionSequence;
    typedef typename FunctionSequence::iterator FunctionIterator; 

private:
    DataType dataElement;
    FunctionSequence funcs;

public:

    void InitGet(DataType DataElement)
    {
        dataElement = DataElement;
    }

    // Function for adding subscribers functions
    // use something like std::bind(&currentClassName::FunctionToAdd, this, std::placeholders::_1) to add function to vector
    void Add(Function f)
    {
        funcs.push_back(f);
    }

};
#endif // _IGraphElement_h_

Upvotes: 1

Views: 537

Answers (1)

James McNellis
James McNellis

Reputation: 355079

If you are using boost::bind you need to use boost::placeholders. You can't mix-and-match.

(Visual C++ 2008 doesn't even include std::placeholders, though; the TR1 service pack includes std::tr1::placeholders, but the C++0x std::placeholders wasn't introduced until Visual C++ 2010.)

Upvotes: 2

Related Questions