我正在使用包含DLL的可执行文件。对于我的测试用例,我将代码组合成一个可执行文件。我正在使用Visual Studio 2008和Boost 1.43。我试过研究这个,但还没有找到明确的答案。谢谢您的帮助。是否可以指向类成员的Typedef函数指针?
在我main.h:
#include <string>
//These are normally defined in a seperate DLL
typedef std::string Typedef_func(const std::string & title);
void Register_My_Typedef(Typedef_func*);
//-------------------------------------------
class myClass
{
public:
std::string func_one(const std::string & title);
Typedef_func _test;
void run();
};
在我的main.cpp:
#include "main.h"
#include <boost/bind.hpp>
std::string workingFunc(const std::string & title)
{
return "";
}
int main(int argc, char* argv[])
{
myclass* example;
example->run();
Register_My_Typedef(&workingFunc);//This works.
return 0;
}
void myClass::run()
{
//I want to point a Typedef_func* in a DLL to call myclass::func_one
Typedef_func* tf = boost::bind(&myClass::func_one, this, "test"); //This does not.
Register_My_Typedef(tf);
}
std::string myClass::funcOne(const std::string & title)
{
return "";
}
void Register_My_Typedef(Typedef_func* passedIn)
{
//Points the pointer in the DLL to passedIn
}
的DLL逻辑正常工作时Register_My_Typedef叫不上一个类中的功能,但它是可能从一个类中调用它?当我尝试编译这段代码返回的是:当我尝试
,并在Windows XP中使用VS2008编译我得到:
错误C2440:初始化:不能从 转换“的boost :: _ BI: :bind_t'到'Typedef_func(__cdecl *)' [ R = std :: string, F = boost :: _ mfi :: mf1, L = boost :: _ bi :: list2,boost :: _ bi ::值> ]
没有可执行此操作的用户定义转换操作员 转换,否则操作员不能被调用。