我遇到了 Windows 申请表的组织问题,需要一些帮助。现在代码是在 microsoft studio 2010 的 .net 4.0 中用 c++ 完成的。 GUI 应用程序的头文件未组织,这可能会导致 10,000 行或更多行代码,这使得阅读变得非常困难。
我试图将点击事件实现分离到包含“Form1.h”的 .cpp 文件中。
private:
System::Void sIToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e){
switch(this->USCustomaryFlg){
case true:
this->sIToolStripMenuItem->Checked = true;
this->mnuUSMetric->Checked = false;
this->USCustomaryFlg = false;
cout << "SI flag is now true." << endl;
break;
case false:
break;
}
}
在Form1的.cpp文件中插入此表单:
System::Void mnuUSMetric_Click(System::Object^ sender, System::EventArgs^ e){
switch(this->USCustomaryFlg){
case true:
cout << "USCustomaryFlg is now false." << endl;
break;
case false:
this->mnuUSMetric->Checked = true;
this->USCustomaryFlg = true;
this->sIToolStripMenuItem->Checked = false;
cout << "USCustomaryFlg is now true." << endl;
break;
}
}
我收到的错误只是我收到的错误的一个示例:
Error 2 error C2355:
'this'
: can only be referenced inside non-static member functions E:\Summer 2011\Engineer Software\GUItest\GUItest\Form1.cpp 16Error 4 error C2355:
'this'
: can only be referenced inside non-static member functions E:\Summer 2011\Engineer Software\GUItest\GUItest\Form1.cpp 21Error 3 error C2227: left of
'->USCustomaryFlg'
must point to class/struct/union/generic type E:\Summer 2011\Engineer Software\GUItest\GUItest\Form1.cpp 16Error 8 error C2227: left of
'->USCustomaryFlg'
must point to class/struct/union/generic type E:\Summer 2011\Engineer Software\GUItest\GUItest\Form1.cpp 22
对此有什么想法吗?
最佳答案
如果您的 C++ 方法是与其声明(即它在类内部的签名)分开定义的(即编写其主体),则需要在方法定义前加上前缀类(class)名称。
例如如果您的类名为 MyForm
,则定义应为
System::Void MyForm::mnuUSMetric_Click(System::Object^ sender, System::EventArgs^ e){
...
}
关于header - 将点击事件从 .h(设计器代码)分离到 .cpp 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6419385/