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甚至不包括
\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(¤tClassName::FunctionToAdd, this, std::placeholders::_1) to add function to vector
void Add(Function f)
{
funcs.push_back(f);
}
};
#endif // _IGraphElement_h_