Boost / std bind, как решить такие ошибки?(функция привязки из одного класса в другой класс) - PullRequest
1 голос
/ 31 января 2011

Итак, я пытаюсь создать простой график, соединяющий один класс с другим ...

#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);
    }

};

Но он дает мне C3083 и C2039 в строке (**) ... Я использую против 2008Я не могу SED связать ... как решить такую ​​проблему?

BTW #include "IGraphElement.h" выглядит как

#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_

1 Ответ

2 голосов
/ 31 января 2011

Если вы используете boost::bind, вам нужно использовать boost::placeholders.Вы не можете смешивать и сочетать.

(хотя Visual C ++ 2008 даже не включает std::placeholders; пакет обновления TR1 включает std::tr1::placeholders, но C ++ 0x std::placeholders не был представлен до Visual C ++ 2010.)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...