Error c2143

Hi. I am very new to programming and especially new to Visual Studios (2008). I am creating my first Windows Forms Application and have been dealing with this error code for a while (error C2143: syntax error: missing ';' before 'private' - on line 35). I've checked all my header files and nowhere is a ';' missing. What else could this error mean?

Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#pragma once
#include "RowsReader.h"
#include <msclr\marshal_cppstd.h>

using namespace msclr::interop;

namespace WindowsFormsApplication2 {

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

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
	public:
		Form1(void)
		{
			InitializeComponent();
			
			//TODO: Add the constructor code here
			
		private: System::Void Form1_Load_1(System::Object^  sender, System::EventArgs^  e) {
				 }
		}

	protected:
		//
		/// Clean up any resources being used.
		//
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::RichTextBox^  richTextBox1;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;

	private: System::Windows::Forms::RichTextBox^  richTextBox2;
	private: System::Windows::Forms::RichTextBox^  richTextBox3;


	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->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
			this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
			this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(385, 104);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(24, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"...";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// richTextBox1
			// 
			this->richTextBox1->Location = System::Drawing::Point(87, 104);
			this->richTextBox1->Name = L"richTextBox1";
			this->richTextBox1->Size = System::Drawing::Size(281, 23);
			this->richTextBox1->TabIndex = 1;
			this->richTextBox1->Text = L"";
			this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBox1_TextChanged);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(44, 107);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(37, 13);
			this->label1->TabIndex = 2;
			this->label1->Text = L"Rows:";
			// 
			// openFileDialog1
			// 
			this->openFileDialog1->FileName = L"openFileDialog1";
			// 
			// richTextBox2
			// 
			this->richTextBox2->Location = System::Drawing::Point(87, 210);
			this->richTextBox2->Name = L"richTextBox2";
			this->richTextBox2->Size = System::Drawing::Size(281, 260);
			this->richTextBox2->TabIndex = 4;
			this->richTextBox2->Text = L"";
			this->richTextBox2->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBox2_TextChanged);
			// 
			// richTextBox3
			// 
			this->richTextBox3->Location = System::Drawing::Point(385, 210);
			this->richTextBox3->Name = L"richTextBox3";
			this->richTextBox3->Size = System::Drawing::Size(268, 260);
			this->richTextBox3->TabIndex = 5;
			this->richTextBox3->Text = L"";
			this->richTextBox3->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBox3_TextChanged);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(677, 520);
			this->Controls->Add(this->richTextBox3);
			this->Controls->Add(this->richTextBox2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->richTextBox1);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

      if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
      {
         System::IO::StreamReader ^ sr = gcnew

            System::IO::StreamReader(openFileDialog1->FileName);
		 richTextBox1->Text = openFileDialog1->FileName;
		 richTextBox2->Text = Convert::ToString(sr->ReadToEnd());
		 richTextBox3->Text = Convert::ToString(tokenVector[1]); 
		
		 std::string rows(marshal_as<std::string>(richTextBox2->Text));
		 RR(rows);
		 sr->Close();
	  }
	}
	private: System::Void richTextBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		}
	private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
		

		 }
private: System::Void richTextBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void richTextBox3_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}
closed account (3qX21hU5)
Your added a private label inside of a member function which can't be done. Delete the private label on line 35.

Also this isn't java or C# access labels go on until they hit another label so you don't need to declare one for every member :).

For example

1
2
3
4
5
6
7
8
9
10
class Stuff
{
    public:
        int one;
        int two;
        int someFunction()

        // Everything above the private label is public 
    private:
}
When I do so, I get this error: C2601: 'Form1_Load_1' : local function definitions are illegal (line 35).

Sorry, I'm a little helpless because I didn't write this code, it was generated as I created and edited the Form1.h design
closed account (3qX21hU5)
Hmm actually you know what I should have look at your post closer. I don't really have much experience with C++ and windows Forms (Personally prefer QT) so I am more then likely wrong on this one. So I will let someone with more experience answer this for you.

Another word of advice might be to move this thread to the windows forum.
Fair enough, thanks for the suggestion! Maybe I would have more success with QT...
There's nothing mysterious about the errors you are receiving.

You've got a function definition inside another function definition.

1
2
3
4
5
6
7

public :
	Form1(void) {
		initializeComponent();
		System::Void Form1_Load_1(System::Object^ sender, System::EventArgs^ e) {
		}
	}
Topic archived. No new replies allowed.