Windows窗体 - 单个实例 - 包含语句

时间:2012-06-12 17:40:12

标签: c++ winforms visual-c++ c++-cli

当我尝试在“For_Student_Details.h”形式中使用#include“CFIS_Main.h”语句时, 它不接受......任何人都可以指出我的错误?谢谢你的帮助......

MyProject.cpp
// MyProject.cpp : main project file.

#include "stdafx.h"

#ifndef CFIS_Main_h
#define CFIS_Main_h
#include "CFIS_Main.h"
#endif

using namespace MyProject;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    // Create the main window and run it
    Application::Run(gcnew CFIS_Main());
    return 0;
}

我的代码来自MdiParent

//CFIS_Main.h  IsMdiContainer = True

#include "For_Student_Detials"


private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
For_Student_Detials^ MyStudentDet= For_Student_Detials::GetForm(true,this);
MyStudentDet->MdiParent=this;
MyStudentDet->FormBorderStyle=System::Windows::Forms::FormBorderStyle::None;
MyStudentDet->Dock=DockStyle::Fill;
MyStudentDet->Show();
}

我的代码来自MdiChild For_Student_Details

#include "CFIS_Main.h"  Why Not included...?????

public: static For_Student_Details^ For_Student_Details::_instance = nullptr;
public: static For_Student_Details^ For_Student_Details::GetForm(bool^ IsMDIChild, CFIS_Main^ MyInstFrm) {
if (_instance == nullptr)
    _instance = gcnew For_Student_Details();

if (_instance->IsDisposed)
    _instance = gcnew For_Student_Details();

if (IsMDIChild)
    _instance->MdiParent = MyInstFrm;

return _instance;
} 

收到以下错误

error C2061: syntax error : identifier 'CFIS_Main'
error C2065: 'MyInstFrm' : undeclared identifier
error C2660: 'CashFlow_InformationsSystem::For_Loan_Details::GetForm' : function does not take 2 arguments

从上面的代码来看,它不包括CFIS_Main,我无法识别我的错误,有人能指出我吗? 谢谢你的帮助

1 个答案:

答案 0 :(得分:2)

您有一个循环标题引用:

  • “For_Student_Details”包括“CFIS_Main.h”
  • “CFIS_Main.h”包含“For_Student_Details”

您需要解决此循环依赖关系。

最简单的方法是在“CFIS_Main.h”中仅保留button1_Click()的函数声明,并将定义移到“MyProject”中。 cpp“,其中还包括”For_Student_Details“。

您还必须定义(或包含正确的标题)CFIS_Main中引用的类型For_Student_Details::GetForm()(修复循环包含问题后可能会解决此问题)

此外,将包含警卫放在头文件中,而不是.cpp文件