求助! C++ 回调函数的使用
我的工程中。
定了一个类 WordStatProcessor.h
#pragma once#include <string>#include <iostream>#include <fstream>namespace WordStat { class WordStatProcessor { public: void WordStatProcessor::process(void(*callback)(std::string str)); private: };}
#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()); }};}