GUI表单 - 在按钮单击时从头文件中的表单cpp文件调用函数 [英] GUI Form - call function from forms cpp file from header file on button click
问题描述
你好,
我是c ++的新手。
我创建了一个Windows窗体,它有一个.h文件和一个.cpp文件。
我创建了一个按钮单击事件,我想从窗体cpp文件中调用一个函数。
private:System :: Void btnCompute_Click(System :: Object ^ sender,System :: EventArgs ^ e){
DoSomething(); //在.cpp文件中定义
}
我不知道如何引用.cpp文件中的函数,我得到错误标识符未找到。
任何帮助都将不胜感激。
谢谢
Bill
在.h中你有:
< p style ="margin:0px 0px 10.66px"> 命名空间MyNamespace
{
公开参考等级MyForm
{
&NBSP; &NBSP; 跨度>。 。 。
&NBSP; &NBSP; void DoSomething();
};
}
然后在.cpp中:
命名空间MyNamespace
{
void MyForm :: DoSomething()
{
&NBSP; &NBSP; 跨度>。 。 。
}
}
使用相应的名称。
< /跨度> 跨度>
Hello,
I'm new to c++.
I created a windows form, it has an .h file, and a .cpp file.
I created a button click event, and I want to call a function from the forms cpp file.
private: System::Void btnCompute_Click(System::Object^ sender, System::EventArgs^ e) { DoSomething(); //defined in the .cpp file }
I am not sure how to reference the function in the .cpp file, I get the error identifier not found.
Any help would be appreciated.
Thank you
Bill
In .h you have:
namespace MyNamespace
{
public ref class MyForm
{
. . .
void DoSomething();
};
}
Then in .cpp:namespace MyNamespace
{
void MyForm::DoSomething()
{
. . .
}
}
Use the corresponding names.
这篇关于GUI表单 - 在按钮单击时从头文件中的表单cpp文件调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!