Boost / std bind如何解决这样的错误? (从一个类到另一个类的绑定函数) [英] Boost/std bind how to solve such errors? (binding function from one class to another class)

查看:123
本文介绍了Boost / std bind如何解决这样的错误? (从一个类到另一个类的绑定函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试创建一个简单的图连接一个类到另一个...

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

};

但是它给了我C3083和C2039我不能签约绑定...如何解决这样的问题?

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


推荐答案

正在使用 boost :: bind ,您需要使用 boost :: placeholder 。你不能混合搭配。

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

(Visual C ++ 2008甚至不包括 std :: placeholder ; TR1服务包包括 std :: tr1 :: placeholder ,但C ++ 0x std :: placeholders 直到Visual C ++ 2010。)

(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.)

这篇关于Boost / std bind如何解决这样的错误? (从一个类到另一个类的绑定函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆