编译器错误没有意义(错误是缺少函数参数)
我收到以下编译器错误:
错误:没有匹配的函数可调用 buildTransFunc(
buildTransFunc 的声明如下:
template<typename RT, typename func, typename... Args>
RT buildTransFunc(func f, Args... args)
{
return RT(boost::bind(f, _1, args...));
}
我按如下方式调用上述内容:
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)>, EnumTypeToStringTranslatorType>, boost::function<EnumType(short int)(&enumChecker), EnumTypeToStringTranslator);
错误消息似乎跳过了错误消息中的 std::string (*) (short int, boost::function, EnumTypeToStringTranslatorType&) 参数,如其他一切都在那里。
我使用 GCC 4.5.2 作为编译器。
Translator 函数的声明是:
template<typename RT, typename D, typename... Args>
RT Translator(Args... args)
{
return static_cast<RT>(translate<RT, D>(args...));
}
翻译函数可以在这个问题中找到: 翻译
编辑 更正了对 buildTransFunction 的调用以完成指定参数。
使用的 g++ 参数:-std=c++0x。
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)>, EnumTypeToStringTranslatorType>, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想这个问题的寓意是不要试图太花哨......因为这是通过
简单地使用参数调用 boost::bind ,而不是通过单独的函数转发它们。
所以不要这样:
只需像这样调用:
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:
just do the call like this: