首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

! C++ 回调函数的使用

2012-02-24 
求助! C++ 回调函数的使用我的工程中。定了一个类 WordStatProcessor.hC/C++ code#pragma once#include st

求助! C++ 回调函数的使用

我的工程中。

定了一个类 WordStatProcessor.h

C/C++ code
#pragma once#include <string>#include <iostream>#include <fstream>namespace WordStat {    class WordStatProcessor {        public:        void WordStatProcessor::process(void(*callback)(std::string str));        private:        };}


需要在 Form 里面调用 


C/C++ code
#pragma once#include "WordStatProcessor.h"namespace WordStat {    using namespace System;    using namespace System::ComponentModel;    using namespace System::Collections;    using namespace System::Windows::Forms;    using namespace System::Data;    using namespace System::Drawing;        public ref class Form1 : public System::Windows::Forms::Form    {    public:        Form1(void)        {            InitializeComponent();        }    protected:        ~Form1()        {            if (components)            {                delete components;            }        }        ...    private: System::Windows::Forms::Label^  currentState;        ...    private:        System::ComponentModel::Container ^components;#pragma region Windows Form Designer generated code        void InitializeComponent(void)        {                  ...        }#pragma endregionprivate: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {             WordStat::WordStatProcessor processor;                         // 在这里 调用             processor.process(this->updateStat);                     }private: void updateStat(std::string str){                         // 回调函数 需要更新状态             this->currentState->Text = gcnew String(str.c_str());         }};}


[解决办法]
这个updateStat如果不是静态成员函数是不能这样调用的
[解决办法]
使用委托

热点排行