开发者

Compiler Error doesn't make sense (error is missing parameter to function)

I am getting a compiler error of:

error: no matching function for call to buildTransFunc(<unresloved overloaded function type>, boost::function<EnumType(short int)>, EnumTypeToStringTranslator&)

The declaration for buildTransFunc is as follows:

template<typename RT, typename func, typename... Args>
RT buildTransFunc(func f, Args... args)
{
    return RT(boost::bind(f, _1, args...));
}

I am calling the above as follows:

typedef boost::function<std::string (short int)> toASCIITranslator;
toASCIITranslator temp = buildTransFunction<toASCIITranslator, std::string (*) (short int, boost::function<EnumType(short int)>, EnumTypeToStringTranslatorType&), boost::function<EnumType(short int)>, EnumTypeToStringTranslatorType& >
(&Translator<std::string, forward_trans, short int, boost::function<EnumType (short int)>, EnumTypeToStringTran开发者_JS百科slatorType>, boost::function<EnumType(short int)(&enumChecker), EnumTypeToStringTranslator);

The error message seems to be skipping over the std::string (*) (short int, boost::function, EnumTypeToStringTranslatorType&) parameter in the error message, as everything else is in there.

I'm using GCC 4.5.2 for the compiler.

The declaration for the Translator function is:

template<typename RT, typename D, typename... Args>
RT Translator(Args... args)
{
    return static_cast<RT>(translate<RT, D>(args...));
}

The translate functions can be found in this question: Translate

EDIT corrected call to buildTransFunction to finish specifing parameters.

g++ arguments used: -std=c++0x.


I guess the moral of this question is don't try to be too fancy... as this works by plainly calling boost::bind with the parameters, instead of forwarding them though a seprate function.

so instead of this:

toASCIITranslator temp = buildTansFunc<.....>(....);

just do the call like this:

toASCIITranslator temp = boost::bind(&Translator<std::string, forward_trans, short int, boost::function<EnumType(short int), EnumToStringTranslatorType&>, 
                         _1, 
                         boost::function<EnumType(short int)>(&enumChecker),
                         EnumToStringTranslator);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜