我有一個包含功能 _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