MyForm2:未声明的标识符
MyForm2: undeclared identifier
我已经为这个错误苦苦挣扎了一段时间。
我正在尝试实现 ATM 系统的登录,并且我正在尝试将其连接到数据库。但是当我尝试 运行 它时,显示了 144 个完全相同的错误:
'MyForm2': is not a member of 'jiji'
'MyForm2': undeclared identifier
Syntax error: missing ';' before identifier 'f2'
'f2':undeclared identifier
老实说,我不知道为什么会这样。我试图在主代码中包含 MyForm2.h
但没有任何变化。
在这里,我留下了我所有 7 种形式几乎相同的一段代码(除了第二个,我认为这是给出错误的那个)
MyForm.h:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
String^ User = textBox1->Text;
String^ Pwd = textBox2->Text;
int AN = Int32::Parse(textBox3->Text);
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
MySqlConnection^ con = gcnew MySqlConnection(constr);
MySqlDataAdapter^ da = gcnew MySqlDataAdapter("Select AccountNum from Userinfo WHERE AccountNum = '" + AN + "'", con);
DataTable^ dt = gcnew DataTable();
da->Fill(dt);
if (dt->Rows->Count >= 1) {
MySqlCommand^ cmd = gcnew MySqlCommand("insert into Db values (" + AN + ") ", con);
con->Open();
MySqlDataReader^ dr = cmd->ExecuteReader();
con->Close();
try {
this->Hide();
jiji::MyForm2 f2;
f2.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
else {
MessageBox::Show("User does not exist, try again");
}
}
catch (Exception^ e) {
MessageBox::Show(e->Message);
}
}
顺便说一句,AN 是帐号。
MyForm2.h代码一遍又一遍地相同,除了结尾。
MyForm2.h:
//Extract money
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm3 f3;
f3.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Insert Money
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm4 f4;
f4.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Transfer
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm5 f5;
f5.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Check Amount
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm6 f6;
f6.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Reload phone
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm7 f7;
f7.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Exit
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
try {
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
MySqlConnection^ con = gcnew MySqlConnection(constr);
MySqlCommand^ cmd = gcnew MySqlCommand("TRUNCATE Db ", con);
con->Open();
MySqlDataReader^ dr = cmd->ExecuteReader();
con->Close();
}
catch (Exception^ e) {
MessageBox::Show(e->Message);
}
finally {
this->Close();
}
}
也许您没有将 MyForm2.h
包含在 MyForm.h
可以访问的上下文中?
也许研究一下如何声明命名空间以及如何包含 headers,例如Creating a C++ namespace in header and source (cpp)
如果将 MyForm2
class 定义内联到 MyForm
中以保证其可访问,会发生什么情况?
我已经为这个错误苦苦挣扎了一段时间。
我正在尝试实现 ATM 系统的登录,并且我正在尝试将其连接到数据库。但是当我尝试 运行 它时,显示了 144 个完全相同的错误:
'MyForm2': is not a member of 'jiji'
'MyForm2': undeclared identifier
Syntax error: missing ';' before identifier 'f2'
'f2':undeclared identifier
老实说,我不知道为什么会这样。我试图在主代码中包含 MyForm2.h
但没有任何变化。
在这里,我留下了我所有 7 种形式几乎相同的一段代码(除了第二个,我认为这是给出错误的那个)
MyForm.h:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
String^ User = textBox1->Text;
String^ Pwd = textBox2->Text;
int AN = Int32::Parse(textBox3->Text);
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
MySqlConnection^ con = gcnew MySqlConnection(constr);
MySqlDataAdapter^ da = gcnew MySqlDataAdapter("Select AccountNum from Userinfo WHERE AccountNum = '" + AN + "'", con);
DataTable^ dt = gcnew DataTable();
da->Fill(dt);
if (dt->Rows->Count >= 1) {
MySqlCommand^ cmd = gcnew MySqlCommand("insert into Db values (" + AN + ") ", con);
con->Open();
MySqlDataReader^ dr = cmd->ExecuteReader();
con->Close();
try {
this->Hide();
jiji::MyForm2 f2;
f2.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
else {
MessageBox::Show("User does not exist, try again");
}
}
catch (Exception^ e) {
MessageBox::Show(e->Message);
}
}
顺便说一句,AN 是帐号。
MyForm2.h代码一遍又一遍地相同,除了结尾。
MyForm2.h:
//Extract money
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm3 f3;
f3.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Insert Money
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm4 f4;
f4.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Transfer
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm5 f5;
f5.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Check Amount
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm6 f6;
f6.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Reload phone
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm7 f7;
f7.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Exit
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
try {
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
MySqlConnection^ con = gcnew MySqlConnection(constr);
MySqlCommand^ cmd = gcnew MySqlCommand("TRUNCATE Db ", con);
con->Open();
MySqlDataReader^ dr = cmd->ExecuteReader();
con->Close();
}
catch (Exception^ e) {
MessageBox::Show(e->Message);
}
finally {
this->Close();
}
}
也许您没有将 MyForm2.h
包含在 MyForm.h
可以访问的上下文中?
也许研究一下如何声明命名空间以及如何包含 headers,例如Creating a C++ namespace in header and source (cpp)
如果将 MyForm2
class 定义内联到 MyForm
中以保证其可访问,会发生什么情况?