Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Boost/std绑定如何解决此类错误?(将函数从一个类绑定到另一个类)_C++_Visual Studio_Visual Studio 2008_Boost - Fatal编程技术网

C++ Boost/std绑定如何解决此类错误?(将函数从一个类绑定到另一个类)

C++ Boost/std绑定如何解决此类错误?(将函数从一个类绑定到另一个类),c++,visual-studio,visual-studio-2008,boost,C++,Visual Studio,Visual Studio 2008,Boost,所以我想创建一个简单的图形,将一个类连接到另一个类 #include "IGraphElement.h" #include <boost/bind.hpp> class simpleRendererGraphElement : public IGraphElementBase, public simpleRendererLibAPI { public: IGraphElement<ExtendedCharPtr>* charGenerator; //

所以我想创建一个简单的图形,将一个类连接到另一个类

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

};

如果您使用的是
boost::bind
,则需要使用
boost::占位符
。你不能混搭


(Visual C++ 2008甚至不包括 STD::占位符< /C>);Tr1服务包包括<>代码> STD::Tr1:占位符< /C> >,但是C++ 0x<代码> STD::占位符< /C> >直到VisualC++ 2010才被引入。

以及如何在VS08中解决这种情况-有没有办法去掉占位符?但是我在boost中没有看到boost::placeholder的标题,只有boost::is_占位符=(VS08的占位符从何处获得增强?显然,它们已被移动到未命名的命名空间中,可以简单地称为
\u 1
\u 2
,等等。请参阅。
#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_