(boost:: && std::) 绑定仅在参数太少的 MSVC 上失败
(boost:: && std::) bind fails only on MSVC with too few arguments
编辑:最小化代码示例
#include <iostream>
#include <functional>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <Wt/WServer>
Wt::WApplication *createApplication(const Wt::WEnvironment& env, int i) {
return new Wt::WApplication(env);
}
int main(int argc, char** argv)
{
Wt::WRun(argc, argv,boost::bind(&createApplication, _1, 1));
}
错误94错误C2198: 'Wt::WApplication *(__cdecl *)(const Wt::WEnvironment &,int)':调用 Wt -3.3.4-msvs2013-windows-x86-sdkincludeboostfunctionfunction_template.hpp 95 1
在Wt::WRun(argc, argv,std::bind(&createApplication, std::placeholders::_1, 1));
中也会失败,并出现完全相同的错误。
老例子
我正在使用库Wt,它具有函数Wt::WRun()
,作为函数的第三个参数,在这种情况下,application_creator
,返回一个指向Wt类型的指针,并接受一个参数。到目前为止一切顺利。这个函数是用户提供的,可能需要更多的参数,我这样做了,并且还提供了一个库示例(参见main.c, Wt::WSever::addEntryPoint
接受与WRun
相同的参数)。
所以我想绑定我的附加参数,就像在例子中一样。我的解决方案与gcc/mingw完美编译,但与MSVC/Visual Studio 2013 Express,它失败的错误
错误94错误C2198: 'Wt::WApplication *(__cdecl *)(const Wt::WEnvironment &,int)':调用参数太少…包括boostfunctionfunction_template.h
My call: Wt::WRun(argc, argv,boost::bind(MDDB_Service::application_creator, _1, 5));
回调函数Wt::WApplication* MDDB_Service::application_creator(const Wt::WEnvironment& env, int foo);
的定义
WT::WRun
定义:
#define WTCONNECTOR_API __declspec(dllimport)
typedef boost::function<WApplication* (const WEnvironment&)> ApplicationCreator;
int WTCONNECTOR_API WRun(int argc, char** argv,
ApplicationCreator createApplication = 0);
同理,Wt::WRun(argc, argv,std::bind(MDDB_Service::application_creator, std::placeholders::_1, 5));
错误94错误C2198: 'Wt::WApplication *(__cdecl *)(const Wt::WEnvironment &,int)':调用参数太少…包括促进函数 function_template.hpp
问题实际上不是编译器的错,而是这一行:
Wt::WEnvironment we();
声明了一个名为we
的函数,不带参数,返回一个Wt::WEnvironment
。你正在成为最令人烦恼的解析的受害者。
用
Wt::WEnvironment we;
应该可以解决您的问题。
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- variadic模板中的模板参数推导失败
- 当给定默认值时,为什么此模板参数推导失败
- 模板参数推导失败,函数参数/参数不匹配
- 为什么模板参数推导失败?
- 嵌套参数包扩展失败
- 模板参数的 C++ 自动模板推导失败
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 失败,出现错误 87:参数不正确.如何判断哪个参数不正确?
- 在 g++ 6.2.1 中将参数包转发到 constructor() 失败
- 当变量和参数名称匹配时,移动语义构造失败
- 作为模板参数的成员函数指针在继承的成员函数上失败,如何以及为什么?
- 模板参数推导/替换失败,lambda作为函数指针
- 调用基函数时模板参数推导失败
- 类模板参数推导失败会导致替换失败
- 折叠表达式模板参数推导/替换失败
- 结果失败或多个参数无效