1
我想要使用自定義的.NET引用類來控制按鈕系統。它由添加到父窗體的類中的PictureBox組成。當它檢測到點擊時,它需要調用構造函數中指定的函數,該構造函數是父類中的方法。指針到成員函數在參考類
例如:
//in the custom class file
public ref class CButton {
private: void (*callingproc)(void);
public:
CButton(void (*cproc)(void)) {
callingproc = cproc;
}
button_dowork() {
//do our code to detect if the click was in the right place and call our proc
callingproc();
}
};
//in the form.h
void cp(void) {
//do our form work
}
void Form_CreateCButton() {
CButton^ t = gcnew CButtom(cp);
}
上面導致沿着線錯誤「使用&納秒::形式:: CP創建指針構件」,其次是「指針到構件無效爲受管理的類「當我按照說明。有任何想法嗎?
您*必須*在此處使用委託。在C++/CLI編程的任何介紹性文章中都有涵蓋。 – 2013-03-26 00:18:15
從C++重新標記爲C++ - CLI – JBentley 2013-03-26 01:31:13
「在C++/CLI編程的任何介紹性文本中都有詳細介紹」 - 任何鏈接到此的機會? – Dave 2015-01-09 12:05:15