GUI表单 - 在按钮单击时从头文件中的表单cpp文件调用函数 [英] GUI Form - call function from forms cpp file from header file on button click

查看:61
本文介绍了GUI表单 - 在按钮单击时从头文件中的表单cpp文件调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆