2016-01-20 192 views
0

嗨,我試圖創建一個函數,想要在Windows窗體嚮導中創建窗體的類的類。 Visual Studio使用項目名稱作爲Form類的名稱空間'NewCustomerForm',但是當我試圖創建一個函數時,該類作爲參數說明我編譯代碼時出現此錯誤消息:C++ Visual Studio 2015 CLR Windows窗體命名空間錯誤

Error C2871 'Project1': a namespace with this name does not exist 

這是它NewCustomerTab.h抱怨文件:

#ifndef __NewCustomerTab_H__ 
#define __NewCustomerTab_H__ 

#include "NewCustomerForm.h" 

using namespace Project1; 

ref class CNewCustomerTab : 
    public System::Windows::Forms::TabPage{ 
public: 
    CNewCustomerTab(NewCustomerForm^); 
private: 
    System::Windows::Forms::Form^ form1; 
}; 

這是Form類NewCustomerForm.h

#pragma once 

#include "NewCustomerTab.h" 

namespace Project1 { 

    using namespace System; 
    using namespace System::ComponentModel; 
    using namespace System::Collections; 
    using namespace System::Windows::Forms; 
    using namespace System::Data; 
    using namespace System::Drawing; 

    /// <summary> 
    /// Summary for NewCustomerForm 
    /// </summary> 
    public ref class NewCustomerForm : public Form 
    { 
    public: 
     NewCustomerForm(void) 
     { 
      InitializeComponent(); 
      // 
      //TODO: Add the constructor code here 
      // 
     } 

    protected: 
     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     ~NewCustomerForm() 
     { 
      if (components) 
      { 
       delete components; 
      } 
     } 
    public: System::Windows::Forms::Panel^ panel1; 
    private: System::Windows::Forms::Label^ label1; 
    protected: 

    private: 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     System::ComponentModel::Container ^components; 

#pragma region Windows Form Designer generated code 
     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     void InitializeComponent(void) 
     { 
      this->panel1 = (gcnew System::Windows::Forms::Panel()); 
      this->label1 = (gcnew System::Windows::Forms::Label()); 
      this->panel1->SuspendLayout(); 
      this->SuspendLayout(); 
      // 
      // panel1 
      // 
      this->panel1->Controls->Add(this->label1); 
      this->panel1->Dock = System::Windows::Forms::DockStyle::Fill; 
      this->panel1->Location = System::Drawing::Point(0, 0); 
      this->panel1->Name = L"panel1"; 
      this->panel1->Size = System::Drawing::Size(842, 563); 
      this->panel1->TabIndex = 0; 
      // 
      // label1 
      // 
      this->label1->AutoSize = true; 
      this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(0))); 
      this->label1->Location = System::Drawing::Point(251, 31); 
      this->label1->Name = L"label1"; 
      this->label1->Size = System::Drawing::Size(229, 37); 
      this->label1->TabIndex = 0; 
      this->label1->Text = L"New Customer"; 
      // 
      // NewCustomerForm 
      // 
      //this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
      //this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
      this->ClientSize = System::Drawing::Size(842, 563); 
      this->Controls->Add(this->panel1); 
      this->Name = L"NewCustomerForm"; 
      this->Text = L"NewCustomerForm"; 
      this->panel1->ResumeLayout(false); 
      this->panel1->PerformLayout(); 
      this->ResumeLayout(false); 

     } 
#pragma endregion 
    }; 
} 

我該怎麼辦w^rong我包含Form類文件,並且它表示Project1是一個名稱空間。

+0

你的NewCustomerForm.h在*之前有一個#include *它聲明瞭命名空間。請注意您具有的循環依賴關係,NewCustomerForm.h需要包含NewCustomerTab.h,並且NewCustomerTab.h需要包含NewCustomerForm.h。這是行不通的。你必須用不完整的類型聲明來完成C++舞蹈,並將代碼移動到包含兩個.h文件的.cpp文件中。或者編寫更好的代碼,理想情況下,CNewCustomerTab類不需要知道它正在被NewCustomerForm類使用。建議使用C#語言來執行此操作。 –

+0

感謝漢斯,它是造成問題的包括。 –

回答

0

您必須使用公共語言運行時支持(/ clr)進行編譯。 右鍵單擊您的解決方案,在配置屬性中選擇常規,然後選擇公共語言運行時支持的clr。

+0

就像一句話;這是一個項目設置,而不是解決方案設置。 – Stardidi

相關問題