c++ - Windows 窗体 - 单实例 - 包含语句

标签 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,我无法确定我的错误,有人可以指点我吗? 感谢您的帮助

最佳答案

你有一个循环标题引用:

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

您需要解决这种循环依赖。

最简单的方法是在“CFIS_Main.h”中只保留 button1_Click() 的函数声明,并移动定义 进入“MyProject.cpp”,其中还包含“For_Student_Details”。

您还必须定义(或包含正确的 header )For_Student_Details::GetForm() 中引用的类型 CFIS_Main(一旦您修复循环包含问题)

此外,将 include guard 放在头文件中,而不是 .cpp 文件中

关于c++ - Windows 窗体 - 单实例 - 包含语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11001904/

相关文章:

c++ - 在按钮上运行外部 .exe 单击 c++。如何?

c++ - 如何为MS VC++开发的C++程序分配特定段的代码

c++ - 在 Visual C++ 中接收关于 fgets() 的访问冲突错误

c++ - 为什么没有透明的 C++1x std::map::at?

C++知识产权保护/反逆向

c# - Access 是否仅限于连接数据库并运行查询的用户数量?

C# 窗体 : Print ListView Contents

c++ - boost::transform_iterator 不适用于 std::bind( &Pair::first, _1 )?

c++ - 不确定在尝试扩展我的堆栈功能时是否使用继承

C# Windows 窗体应用程序 - 从另一个线程和类更新 GUI?