
[英]std::bind: error: too few arguments to function call, single argument was not specified
[英](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-sdk \\ include \\ boost的参数太少\\ function \\ function_template.hpp 95 1
Wt::WRun(argc, argv,std::bind(&createApplication, std::placeholders::_1, 1));
失败并显示Wt::WRun(argc, argv,std::bind(&createApplication, std::placeholders::_1, 1));
具有完全相同的错误。
我正在使用具有函数Wt::WRun()
的库Wt ,该函数将一个函数作为第三个参数,在本例中为application_creator
,该函数返回指向Wt类型的指针并接受一个参数。 到现在为止还挺好。 该功能是由用户提供,并可能需要更多的参数,这是我做的,也是一个例子的11b显示(见main.c中, Wt::WSever::addEntryPoint
采用相同的参数作为WRun
)。
因此,我想像示例中那样绑定其他参数。 我的解决方案可以使用gcc / mingw完美编译,但是使用MSVC / Visual Studio 2013 Express时,它会失败并显示以下错误
错误94错误C2198:'Wt :: WApplication *(__ cdecl *)(const Wt :: WEnvironment&,int)':调用的参数太少... include \\ boost \\ function \\ function_template.h
我的电话: 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)':调用的参数太少了... include \\ boost \\ function \\ function_template.hpp
问题实际上不是编译器的错误,而是以下行:
Wt::WEnvironment we();
它声明了一个名为we
带任何参数并返回Wt::WEnvironment
。 您正在成为最令人头疼的分析的受害者。
替换为
Wt::WEnvironment we;
应该解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.