C++ Windows Form - undeclared identifier - Help!

I'm new to C++ and I'm using Visual Studio 2010, Windows Form designer to make my UI. It gives me these errors and I don't know why...

Error(s):
1
2
3
1>ui.cpp(11): error C2065: 'ui' : undeclared identifier
1>ui.cpp(11): error C2146: syntax error : missing ';' before identifier 'obj'
1>ui.cpp(11): error C2065: 'obj' : undeclared identifier


ui.cpp
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>
#include <fstream>
#include "ui.h"

using namespace std;

int main()
{
	ui obj;
}


ui.h
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
#pragma once
#using <mscorlib.dll>

namespace Project_Program {

	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 for ui
	public ref class ui : public System::Windows::Forms::Form
	{
		public:
			ui(void)
			{
				InitializeComponent();
				//Constructor code
			}

		protected:
			/// Clean up any resources being used.
			~ui()
			{
				if (components)
				{
					delete components;
				}
			}

		private: System::Windows::Forms::Button^  loginBtn;
		private: System::Windows::Forms::Button^  regBtn;
		private: System::Windows::Forms::Label^  headerLabel;
		private: System::Windows::Forms::TextBox^  loginText;
		private: System::Windows::Forms::TextBox^  passwordText;
		protected: 
		private:
			/// Required designer variable.
			System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		void InitializeComponent(void)
		{
			this->loginBtn = (gcnew System::Windows::Forms::Button());
			this->regBtn = (gcnew System::Windows::Forms::Button());
			this->headerLabel = (gcnew System::Windows::Forms::Label());
			this->loginText = (gcnew System::Windows::Forms::TextBox());
			this->passwordText = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// loginBtn
			this->loginBtn->Location = System::Drawing::Point(12, 98);
			this->loginBtn->Name = L"loginBtn";
			this->loginBtn->Size = System::Drawing::Size(130, 23);
			this->loginBtn->TabIndex = 1;
			this->loginBtn->Text = L"Login";
			this->loginBtn->UseVisualStyleBackColor = true;
			// regBtn
			this->regBtn->Location = System::Drawing::Point(142, 98);
			this->regBtn->Name = L"regBtn";
			this->regBtn->Size = System::Drawing::Size(130, 23);
			this->regBtn->TabIndex = 2;
			this->regBtn->Text = L"Register";
			this->regBtn->UseVisualStyleBackColor = true;
			// headerLabel
			this->headerLabel->Location = System::Drawing::Point(12, 9);
			this->headerLabel->Name = L"headerLabel";
			this->headerLabel->Size = System::Drawing::Size(260, 34);
			this->headerLabel->TabIndex = 5;
			this->headerLabel->Text = L"Please login or register below. All details are kept private and confidential.";
			// loginText
			this->loginText->Location = System::Drawing::Point(12, 46);
			this->loginText->Name = L"loginText";
			this->loginText->Size = System::Drawing::Size(260, 20);
			this->loginText->TabIndex = 6;
			this->loginText->Text = L"Username";
			// passwordText
			this->passwordText->Location = System::Drawing::Point(12, 72);
			this->passwordText->Name = L"passwordText";
			this->passwordText->Size = System::Drawing::Size(260, 20);
			this->passwordText->TabIndex = 7;
			this->passwordText->Text = L"Password";
			// ui2
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 132);
			this->Controls->Add(this->passwordText);
			this->Controls->Add(this->loginText);
			this->Controls->Add(this->headerLabel);
			this->Controls->Add(this->regBtn);
			this->Controls->Add(this->loginBtn);
			this->Name = L"ui2";
			this->Tag = L"windowMain";
			this->Text = L"Login / Register";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	};
}

You placed the definition of class ui in namespace Project_Program but in main you use unqualified name ui. So the compiler reports the error.
Thanks, I did this in my ui.cpp and it worked :) It only ran a CMD and gave me an error about a PDB file.

Project_Program::ui obj;
Topic archived. No new replies allowed.