2015-11-17 141 views
-4

這是有錯誤的代碼的一部分。我收到一個錯誤,我不知道爲什麼?

#include "MyForm.h" 
; using namespace System; 
using namespace System::Windows::Forms; 

[STAThread] 
void main(array<String^>^ args) 
{ 
Application::EnableVisualStyles(); 
Application::SetCompatibleTextRenderingDefault(false); 

V_Hello_World::MyForm form; 
Application::Run(%form); 
} 

錯誤是:錯誤1錯誤C1075:在左括號'{'之前找到文件的結尾。我不知道爲什麼會發生此錯誤,但有些幫助將非常感謝。

MyForm.h

#pragma once 

namespace V_Hello_World { 

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 MyForm 
/// </summary> 
public ref class MyForm : public System::Windows::Forms::Form 
{ 
public: 
    MyForm(void) 
    { 
     InitializeComponent(); 
     // 
     //TODO: Add the constructor code here 
     // 
    } 

    protected: 
    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    ~MyForm() 
    { 
     if (components) 
     { 
      delete components; 
     } 
    } 
    private: System::Windows::Forms::Button^ button1; 
    protected: 

    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->button1 = (gcnew System::Windows::Forms::Button()); 
     this->SuspendLayout(); 
     // 
     // button1 
     // 
     this->button1->Font = (gcnew System::Drawing::Font(L"Minion Pro", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
      static_cast<System::Byte>(0))); 
     this->button1->Location = System::Drawing::Point(12, 12); 
     this->button1->Name = L"button1"; 
     this->button1->Size = System::Drawing::Size(260, 237); 
     this->button1->TabIndex = 0; 
     this->button1->Text = L"Say Hello"; 
     this->button1->UseVisualStyleBackColor = true; 
     this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); 
     // 
     // MyForm 
     // 
     this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
     this->ClientSize = System::Drawing::Size(284, 261); 
     this->Controls->Add(this->button1); 
     this->Name = L"MyForm"; 
     this->Text = L"MyForm"; 
     this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load); 
     this->ResumeLayout(false); 

    } 
#pragma endregion 
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
    { 
     MessageBox::Show("Hello World!"); 
    } 
}; 
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { 
} 
} 
+3

問題可能出現在「MyForm.h」中 – NathanOliver

+1

這是C++/CLI和WinForms,而不是C++。 – crashmstr

+0

您可以將「MyForm.h」的內容添加到您的問題中嗎? –

回答

1

你開始在

#pragma endregion 
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
    { 
     MessageBox::Show("Hello World!"); 
    } 
}; 
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { 
} 
} 

你的第一個問題,運行的問題是你有button1_Click兩個開放的花括號,但只有一個右括號。你應該能夠刪除一個開放的大括號。你的第二個問題是MyForm_Load在班級體外。你需要把它移到類聲明中。

+0

我試圖刪除兩個括號,而不是在同一時間,當我這樣做時,它開始強調其他一些紅色的東西,說它錯了。 – Punny

+0

@Punny你明白了嗎?我看到你把答案放在答案上。 – NathanOliver

+0

大多數情況下,我想是的,但原來的錯誤再次彈出,我想我會離開你們都是,並不斷嘗試弄清楚。對不起,如果我浪費你的時間。 ; / – Punny

相關問題