错误:应在';之前使用主表达式';代币 >好吧,我在学校里应该做的C++程序有问题,我需要一些帮助,我一直在犯错误。我有基础知识,但我需要类和对象方面的帮助 #include <cstdlib> #include <iostream> #include <string> using namespace std; class BankAccount { private: double accountBalance; string name; public: BankAccount(); BankAccount(string,double); double deposit(double); double withdraw(double); void checkBalance(); }; BankAccount::BankAccount() { accountBalance=0; name=""; } BankAccount::BankAccount(string name,double money) { name=name; accountBalance=accountBalance; } double BankAccount::deposit(double money) { accountBalance+=money; return accountBalance; } double BankAccount::withdraw(double money) { accountBalance-=money; return accountBalance; }; void BankAccount::checkBalance() { cout<<"The balance on the account is $"<<accountBalance<<"!!"<<endl; }; int main(int argc, char *argv[]) { int c; double m; string n; cout<<"==================Bank======="<<endl; cout<<"[1] Open a new Bank Account |"<<endl; cout<<"[2] Deposit money |"<<endl; cout<<"[3] Withdraw money |"<<endl; cout<<"[4] Check balance |"<<endl; cout<<"============================="<<endl; cout<<endl; cout<<"What would you like to do :"; cin>>c; switch (c){ case 1: cout<<"Ok I see you want to open a new Bank Account"<<endl; cout<<"But first answer a few questions:"<<endl; cout<<"What is your name? "; cin>>n; cout<<"Next tell me the amount of money you wish to open your account with: "; cin>>m; BankAccount::BankAccount(n,m); cout<<"OK all set, "<<n<<"!!"<<endl; break; case 2: cout<<"How much money would you like to deposit? : "; cin>>m; BankAccount.deposit(m); break; case 3: cout<<"How much money would you like to withdraw? : "; cin>>m; BankAccount.withdraw(m); break; case 4: cout<<"OK I'll check your balance"<<endl; BankAccount.checkBalance(); break; } system("PAUSE"); return EXIT_SUCCESS; } #包括 #包括 #包括 使用名称空间std; 类别银行帐户{ 私人: 双重账户余额; 字符串名; 公众: 银行账户(); 银行账户(字符串,双); 双倍存款(双倍); 双退(双退); 作废支票余额(); }; BankAccount::BankAccount() { 账户余额=0; name=“”; } BankAccount::BankAccount(字符串名称,双倍货币) { 名称=名称; 账户余额=账户余额; } 双倍银行账户::存款(双倍货币) { 账户余额+=货币; 返回账户余额; } 双倍银行账户:提取(双倍货币) { 账户余额-=货币; 返回账户余额; }; 作废银行账户::支票余额() { cout

错误:应在';之前使用主表达式';代币 >好吧,我在学校里应该做的C++程序有问题,我需要一些帮助,我一直在犯错误。我有基础知识,但我需要类和对象方面的帮助 #include <cstdlib> #include <iostream> #include <string> using namespace std; class BankAccount { private: double accountBalance; string name; public: BankAccount(); BankAccount(string,double); double deposit(double); double withdraw(double); void checkBalance(); }; BankAccount::BankAccount() { accountBalance=0; name=""; } BankAccount::BankAccount(string name,double money) { name=name; accountBalance=accountBalance; } double BankAccount::deposit(double money) { accountBalance+=money; return accountBalance; } double BankAccount::withdraw(double money) { accountBalance-=money; return accountBalance; }; void BankAccount::checkBalance() { cout<<"The balance on the account is $"<<accountBalance<<"!!"<<endl; }; int main(int argc, char *argv[]) { int c; double m; string n; cout<<"==================Bank======="<<endl; cout<<"[1] Open a new Bank Account |"<<endl; cout<<"[2] Deposit money |"<<endl; cout<<"[3] Withdraw money |"<<endl; cout<<"[4] Check balance |"<<endl; cout<<"============================="<<endl; cout<<endl; cout<<"What would you like to do :"; cin>>c; switch (c){ case 1: cout<<"Ok I see you want to open a new Bank Account"<<endl; cout<<"But first answer a few questions:"<<endl; cout<<"What is your name? "; cin>>n; cout<<"Next tell me the amount of money you wish to open your account with: "; cin>>m; BankAccount::BankAccount(n,m); cout<<"OK all set, "<<n<<"!!"<<endl; break; case 2: cout<<"How much money would you like to deposit? : "; cin>>m; BankAccount.deposit(m); break; case 3: cout<<"How much money would you like to withdraw? : "; cin>>m; BankAccount.withdraw(m); break; case 4: cout<<"OK I'll check your balance"<<endl; BankAccount.checkBalance(); break; } system("PAUSE"); return EXIT_SUCCESS; } #包括 #包括 #包括 使用名称空间std; 类别银行帐户{ 私人: 双重账户余额; 字符串名; 公众: 银行账户(); 银行账户(字符串,双); 双倍存款(双倍); 双退(双退); 作废支票余额(); }; BankAccount::BankAccount() { 账户余额=0; name=“”; } BankAccount::BankAccount(字符串名称,双倍货币) { 名称=名称; 账户余额=账户余额; } 双倍银行账户::存款(双倍货币) { 账户余额+=货币; 返回账户余额; } 双倍银行账户:提取(双倍货币) { 账户余额-=货币; 返回账户余额; }; 作废银行账户::支票余额() { cout,c++,C++,BankAccount是一个类型名,而不是变量名。您不能对类型调用实例方法 创建一个类型为BankAccount的变量,为其分配一个实例,然后使用与您已有的相同符号调用实例上的方法: BankAccount acct; switch (c){ case 1: cout<<"Ok I see you want to open a new Bank Account"<<endl; cout<<"But first answer a few qu

BankAccount
是一个类型名,而不是变量名。您不能对类型调用实例方法

创建一个类型为
BankAccount
的变量,为其分配一个实例,然后使用与您已有的相同符号调用实例上的方法:

BankAccount acct;
switch (c){
case 1:
     cout<<"Ok I see you want to open a new Bank Account"<<endl;
     cout<<"But first answer a few questions:"<<endl;
     cout<<"What is your name? ";
     cin>>n;
     cout<<"Next tell me the amount of money you wish to open your account with: ";
     cin>>m;
     acct = BankAccount(n,m);
     cout<<"OK all set, "<<n<<"!!"<<endl;
     break;
case 2:
     cout<<"How much money would you like to deposit? : ";
     cin>>m;
     acct.deposit(m);
     break;
case 3:
     cout<<"How much money would you like to withdraw? : ";
     cin>>m;
     acct.withdraw(m);
     break;
case 4:
     cout<<"OK I'll check your balance"<<endl;
     acct.checkBalance();               
     break;
}
银行账户;
开关(c){
案例1:

cout
BankAccount
是您定义的一个类,您不能使用
运算符访问该类的
非静态成员。在这种情况下,您需要首先创建
BankAccount
的对象,然后使用
点运算符
访问
存款
和其他成员函数,因为这些
n在静态
中,成员函数与类的实例相关联


如果
存款
和其他相关函数是
静态
成员函数,您可以这样做。

您得到的错误是什么?在GCC中,因此他必须拥有Visual Studio