我有一个包含功能 _genericLoadFromFile
命名为DrawerApp
类,Run
传递一个功能到另一个功能相同的类内
我想每个功能_loadFromFileHelper
,_loadFromBinHelper
从Run
函数中调用,如下:
void DrawerApp::Run()
{
_genericLoadFromFile(_loadFromFileHelper);
_genericLoadFromFile(_loadFromBinHelper);
}
而且_genericLoadFromFile
看起来是这样的:
bool DrawerApp::_genericLoadFromFile(static bool (DrawerApp::*helperFunc)(string))
{
/* do some stuff */
string fileName = 'Test';
success = (this->*helperFunc)(fileName);
}
但不幸的是,我得到以下错误:
DrawerApp::_loadFromFileHelper': function call missing argument list;
use '&DrawerApp::_loadFromFileHelper' to create a pointer to member
而且还这样的警告:
Warning 1 warning C4042: 'helperFunc' : has bad storage class
如何执行这正常吗?我不明白我做错了什么。 谢谢
编辑
当我尝试的错误提示,以&DrawerApp::_loadFromFileHelper
我得到另一个错误编辑:
Error 2 error LNK2019: unresolved external symbol "private: bool __thiscall DrawerApp::_loadFromFileHelper(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __thiscall DrawerApp::Run(void)" ([email protected]@@AAEXXZ)
而且
Error 3 error LNK1120: 1 unresolved externals
请考虑使用静态多态(模板)或普通的旧多态。 – Bathsheba
你能举个例子给后者吗? –
这是第一个错误真的是一个链接器错误?它看起来更像是一个编译器错误。 – razeh