2011-01-31 29 views
1

所以我triing創建一個類連接到另一個簡單的圖...Boost/std綁定如何解決這樣的錯誤? (從一個類綁定功能,另一個類)

#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和在線(**)。 ..我用vs 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_ 

回答

2

如果您正在使用boost::bind你需要使用boost::placeholders。你不能混搭。

(VISUAL C++ 2008甚至不包括std::placeholders,雖然,在TR1服務包包括std::tr1::placeholders,但C++ 0x中std::placeholders沒有出臺,直到VISUAL C++ 2010年)

+0

,如何解決這種情況在VS08中 - 有什麼辦法擺脫佔位符? – Rella 2011-01-31 16:53:25

相關問題