Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
组合函数,bind,c++;和托管代码 我有一个C++函数,它希望函数对象(AudioTraceNoTyfFunc)传递给它: class lc_Authenticate { public: typedef enum { kAbort, kContinue } lc_AuthenticateStatus; typedef std::tr1::function<lc_AuthenticateStatus (const string &msg)> AuthenticateNotifyFunc; bool Authenticate(lc_AuthenticateParams &params, AuthenticateNotifyFunc notifyFunc); } class-lc\u认证 { 公众: 类型定义枚举{ 卡波特, K继续 }立遗嘱; typedef std::tr1::函数AuthenticateNotifyFunc; bool认证(lc_认证参数和参数, AuthenticateNotifyFunc); } 在托管C++项目中,我试图定义一个参数,以便传递给上面的函数: public ref class Form1 : public System::Windows::Forms::Form { public: lc_Authenticate::lc_AuthenticateStatus UpdateStatus(const string &msg) { <<DO SOMETHING>> return(lc_Authenticate::kContinue); } void test() { string appKey, appSecret; appKey = GetString(this->appKeyTextBox->Text); appSecret = GetString(this->appSecretTextBox->Text); lc_Authenticate dbauth; lc_AuthenticateParams params(appKey, appSecret); // DOESN'T COMPILE won't let me take address of member function // or know about _1 lc_Authenticate::AuthenticateNotifyFunc func = std::tr1::bind(&Form1::UpdateStatus, this, _1); dbauth.Authenticate(params, func); } }; public ref类Form1:public System::Windows::Forms::Form { 公众: lc_Authenticate::lc_authenticatestus UpdateStatus(常量字符串和消息) { 返回(lc_Authenticate::kContinue); } 无效测试() { 字符串appKey,appSecret; appKey=GetString(此->appKeyTextBox->文本); appSecret=GetString(此->appSecretTextBox->文本); lc_认证dbauth; lc_AuthenticateParams参数(appKey,appSecret); //不编译不会让我获取成员函数的地址 //或了解 lc_Authenticate::AuthenticateNotifyFunc func= std::tr1::bind(&Form1::UpdateStatus,this,_1); dbauth.Authenticate(参数,函数); } }; 我试图实现一种将函数传递给C++方法的通用方法,它不关心传递的函数是静态的还是成员函数。我不清楚如何从托管代码中实现这一点。_C++_.net_C++11_C++ Cli_Tr1 - Fatal编程技术网

组合函数,bind,c++;和托管代码 我有一个C++函数,它希望函数对象(AudioTraceNoTyfFunc)传递给它: class lc_Authenticate { public: typedef enum { kAbort, kContinue } lc_AuthenticateStatus; typedef std::tr1::function<lc_AuthenticateStatus (const string &msg)> AuthenticateNotifyFunc; bool Authenticate(lc_AuthenticateParams &params, AuthenticateNotifyFunc notifyFunc); } class-lc\u认证 { 公众: 类型定义枚举{ 卡波特, K继续 }立遗嘱; typedef std::tr1::函数AuthenticateNotifyFunc; bool认证(lc_认证参数和参数, AuthenticateNotifyFunc); } 在托管C++项目中,我试图定义一个参数,以便传递给上面的函数: public ref class Form1 : public System::Windows::Forms::Form { public: lc_Authenticate::lc_AuthenticateStatus UpdateStatus(const string &msg) { <<DO SOMETHING>> return(lc_Authenticate::kContinue); } void test() { string appKey, appSecret; appKey = GetString(this->appKeyTextBox->Text); appSecret = GetString(this->appSecretTextBox->Text); lc_Authenticate dbauth; lc_AuthenticateParams params(appKey, appSecret); // DOESN'T COMPILE won't let me take address of member function // or know about _1 lc_Authenticate::AuthenticateNotifyFunc func = std::tr1::bind(&Form1::UpdateStatus, this, _1); dbauth.Authenticate(params, func); } }; public ref类Form1:public System::Windows::Forms::Form { 公众: lc_Authenticate::lc_authenticatestus UpdateStatus(常量字符串和消息) { 返回(lc_Authenticate::kContinue); } 无效测试() { 字符串appKey,appSecret; appKey=GetString(此->appKeyTextBox->文本); appSecret=GetString(此->appSecretTextBox->文本); lc_认证dbauth; lc_AuthenticateParams参数(appKey,appSecret); //不编译不会让我获取成员函数的地址 //或了解 lc_Authenticate::AuthenticateNotifyFunc func= std::tr1::bind(&Form1::UpdateStatus,this,_1); dbauth.Authenticate(参数,函数); } }; 我试图实现一种将函数传递给C++方法的通用方法,它不关心传递的函数是静态的还是成员函数。我不清楚如何从托管代码中实现这一点。

组合函数,bind,c++;和托管代码 我有一个C++函数,它希望函数对象(AudioTraceNoTyfFunc)传递给它: class lc_Authenticate { public: typedef enum { kAbort, kContinue } lc_AuthenticateStatus; typedef std::tr1::function<lc_AuthenticateStatus (const string &msg)> AuthenticateNotifyFunc; bool Authenticate(lc_AuthenticateParams &params, AuthenticateNotifyFunc notifyFunc); } class-lc\u认证 { 公众: 类型定义枚举{ 卡波特, K继续 }立遗嘱; typedef std::tr1::函数AuthenticateNotifyFunc; bool认证(lc_认证参数和参数, AuthenticateNotifyFunc); } 在托管C++项目中,我试图定义一个参数,以便传递给上面的函数: public ref class Form1 : public System::Windows::Forms::Form { public: lc_Authenticate::lc_AuthenticateStatus UpdateStatus(const string &msg) { <<DO SOMETHING>> return(lc_Authenticate::kContinue); } void test() { string appKey, appSecret; appKey = GetString(this->appKeyTextBox->Text); appSecret = GetString(this->appSecretTextBox->Text); lc_Authenticate dbauth; lc_AuthenticateParams params(appKey, appSecret); // DOESN'T COMPILE won't let me take address of member function // or know about _1 lc_Authenticate::AuthenticateNotifyFunc func = std::tr1::bind(&Form1::UpdateStatus, this, _1); dbauth.Authenticate(params, func); } }; public ref类Form1:public System::Windows::Forms::Form { 公众: lc_Authenticate::lc_authenticatestus UpdateStatus(常量字符串和消息) { 返回(lc_Authenticate::kContinue); } 无效测试() { 字符串appKey,appSecret; appKey=GetString(此->appKeyTextBox->文本); appSecret=GetString(此->appSecretTextBox->文本); lc_认证dbauth; lc_AuthenticateParams参数(appKey,appSecret); //不编译不会让我获取成员函数的地址 //或了解 lc_Authenticate::AuthenticateNotifyFunc func= std::tr1::bind(&Form1::UpdateStatus,this,_1); dbauth.Authenticate(参数,函数); } }; 我试图实现一种将函数传递给C++方法的通用方法,它不关心传递的函数是静态的还是成员函数。我不清楚如何从托管代码中实现这一点。,c++,.net,c++11,c++-cli,tr1,C++,.net,C++11,C++ Cli,Tr1,您不能通过设计绑定到托管类的实例方法。垃圾收集器在压缩堆时移动对象,导致此情况发生变化。您需要使用托管委托。因此,您无法避免使用本机帮助器类,该类为您的函数提供所需的稳定回调。您可以使用Marshal::GetFunctionPointerForDelegate()从那里返回托管代码。这可以通过实现,但它将非常丑陋。你为什么要这样做?在C++代码和C++ /CLI代码之间有一个清晰的分离是一件好事;将它们紧密地结合在一起会很痛苦。相关:

您不能通过设计绑定到托管类的实例方法。垃圾收集器在压缩堆时移动对象,导致此情况发生变化。您需要使用托管委托。因此,您无法避免使用本机帮助器类,该类为您的函数提供所需的稳定回调。您可以使用Marshal::GetFunctionPointerForDelegate()从那里返回托管代码。

这可以通过实现,但它将非常丑陋。你为什么要这样做?在C++代码和C++ /CLI代码之间有一个清晰的分离是一件好事;将它们紧密地结合在一起会很痛苦。相关: