我理解将成员函数的地址传递给它的类之外的基本问题.我觉得mem_fn()可能是解决方案,但我遇到了具体问题.
我在类p中有一个当前声明为的成员函数
typedef void (*valNamedFlagsCallback)(const int, const bool);
bool valNamedFlags(const OptBlk *operand, const char *description_of_value_or_NULL, const int subscripts[], const char *names[], valNamedFlagsCallback callBack);
Run Code Online (Sandbox Code Playgroud)
在课堂上我试图用valNamedFlags调用
pInstance->valNamedFlags(operand, "Statement types", statementsSubscripts, statementsNames, std::mem_fn(&e::setStatement));
Run Code Online (Sandbox Code Playgroud)
(我从没有mem_fn()开始,但当然有经典的"指向成员函数的指针"问题.我已经尝试了两个&e :: setStatement和plain&setStatement.)
FWIW,setStatement原型为
void setStatement(const int ifcid, const bool isAffirmative);
Run Code Online (Sandbox Code Playgroud)
如果我删除mem_fn()并将setStatement声明为static,则一切正常.我只是指出这是一种说法,我已经消除了所有其他可能的问题; 我唯一的问题是"成员函数指针"问题.不幸的是,setStatement()需要是一个成员函数,而不是静态函数.
我在MS VS 2010中遇到的具体错误是
bool p :: valNamedFlags(const OptBlk*,const char*,const int [],const char*[],p :: valNamedFlagsCallback)':无法从'std :: tr1 :: _ Mem_fn3 <_Rx,_Pmf转换参数5, _Arg0,_Arg1,_Arg2>'到'p :: valNamedFlagsCallback'
我想保持回调声明独立于e类; 也就是说,我不想去
typedef void (*e::valNamedFlagsCallback)(const int, const bool);
Run Code Online (Sandbox Code Playgroud)
因为我想保持比这更普遍.
mem_fn()是正确的解决方案还是我离开基地?如果是这样,我应该如何在valNamedFlags()原型中声明回调?
或者我应该采用不同的方法?
我第一次尝试使用 VS Clone 将 Git 存储库下载到 Visual\xc2\xa0Studio\xc2\xa02019。我正进入(状态
\nCloning into 'C:\\Users\\Charles\\Source\\Repos\\FingerprintGuide'...\nError encountered while cloning the remote repository: Git failed with a fatal error.\nrepository 'https://github.com/xamarin/monodroid-samples/tree/master/FingerprintGuide/' not found\nRun Code Online (Sandbox Code Playgroud)\n任何人都可以验证该文件夹确实存在。我从 Visual\xc2\xa0Studio 外部的 Web 浏览器登录到 Git。Visual\xc2\xa0Studio Git Options 有我正确的 Git 用户名和电子邮件。
\n我可能做错了什么?正如我所说,我是 Git 新手,所以这可能是显而易见的事情。
\n