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