2012-06-12 32 views
0

當我嘗試使用#include「CFIS_Main.h」語句的形式「For_Student_Details.h」, 它不接受...任何人都可以指出我的錯誤?感謝您的幫助..Windows窗體 - 單實例 - 包括語句

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從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; 
} 

//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(); 
} 

我的代碼收到以下錯誤

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 

從以上代碼,它不包括ding CFIS_Main,我找不到我的錯誤,有人可以指點我嗎? 感謝您的幫助

+1

這些都不包括定義'CFIS_Main'類型的文件。看起來你忘記了完全包含其他東西? – cdhowie

回答

2

你有一個圓形頭部參考:

  • 「For_Student_Details」 包括 「CFIS_Main.h」
  • 「CFIS_Main.h」 包括 「For_Student_Details」

您將需要解決這個循環依賴。

這樣做最簡單的方法是隻留下功能聲明button1_Click()在「CFIS_Main.h」和移動定義到「MyProject.cpp」,在這裏你還包括「For_Student_Details」。

你也必須定義(或包含正確的頭)在For_Student_Details::GetForm()引用的類型CFIS_Main(一旦你解決這個圓形包括問題,這可能被解決)

此外,將包括守衛在你的頭文件,而不是.cpp文件

+0

感謝Attila&Cdhowie – user1328559