C++ 银行系统项目[初学者]基本错误
这是我项目的一个文件。我不明白为什么一个括号里有三个错误。 为了记录在案,在这里发布问题之前,我已经多次尝试解决这个问题。我只是在这方面工作了这么长时间,以至于忽略了问题所在。现在又有一双眼睛亮起红灯,告诉我出了什么问题,我现在觉得问这个问题很愚蠢。在我完成这项工作之前,我拒绝休息。但是,再次感谢大家的投入和帮助。 错误: 错误:C++ 银行系统项目[初学者]基本错误,c++,visual-c++,C++,Visual C++,这是我项目的一个文件。我不明白为什么一个括号里有三个错误。 为了记录在案,在这里发布问题之前,我已经多次尝试解决这个问题。我只是在这方面工作了这么长时间,以至于忽略了问题所在。现在又有一双眼睛亮起红灯,告诉我出了什么问题,我现在觉得问这个问题很愚蠢。在我完成这项工作之前,我拒绝休息。但是,再次感谢大家的投入和帮助。 错误: 错误: ----\bankingsystem.h(45) : error C2236: unexpected 'class' 'BankingSystem'. Did you
----\bankingsystem.h(45) : error C2236: unexpected 'class' 'BankingSystem'. Did you forget a ';'?`
----\bankingsystem.h(45) : error C2143: syntax error : missing ';' before '{'`
----\bankingsystem.h(45) : error C2447: '{' : missing function header (old-style formal list?)`
---\bankingsystem.h(72) : fatal error C1020: unexpected #endif`
\ifndef银行系统\u H
#定义银行系统
#包括
#包括
#include//用于允许字符串函数
使用名称空间std;
类别帐户{
公众:
账户(int accountNumberValue、int passCode、string lastName、string firstName、双倍余额);
~Account();
void setFirstName(字符串&);
字符串getFirstName();
void setLastName(字符串&);
字符串getLastName();
void setAccountNumber(int accountNumberValue);
int getAccountNumber();
void setPassCode(int passcode值);
int getPassCode();
无效余额(双倍余额值);
双getBalance();
私人:
字符串名;
字符串lastName;
国际帐户号码;
整数密码;
双平衡;
}//最终类帐户
#endif//Account\u h
类银行系统
{ ---(45)
公众:
BankingSystem();
~BankingSystem();
void addAccount();//选项1
账户查询(int accountId);
void deleteCount();//选项2
账户查询(int accountId);
void AccountInquiry();//选项3
账户查询(int accountId);
void saveAccount();//选项4
账户查询(int accountId);
void loadAccounts();//选项5
账户查询(int accountId);
私人:
向量账户;
};
#endif---(72)
我标记了错误发生的位置,第(45)行和第(72)行
我绝不要求任何人调试我的程序,我只是要求解释为什么会发生这些错误
正如评论中指出的那样:
- 意外类是因为您没有使用
将当前
帐户
类标记为已完成代码>结束后的花括号
}
- 对于单个
\ifndef
- 以及
科目查询的多次声明(int accountId)代码>
#ifndef BANKING_SYSTEM_H
#define BANKING_SYSTEM_H
#include <string> // Used to allow string functions
#include <vector>
class Account {
public:
Account( int accountNumberValue, int passCode, std::string lastName,
std::string firstName, double balance);
~Account();
void setFirstName ( std::string & );
std::string getFirstName();
void setLastName( std::string & );
std::string getLastName();
void setAccountNumber( int accountNumberValue );
int getAccountNumber();
void setPassCode( int passCodeValue );
int getPassCode();
void setBalance( double balanceValue );
double getBalance();
private:
std::string firstName;
std::string lastName;
int accountNumber;
int passCode;
double balance;
}; // end class Account
class BankingSystem
{
public:
BankingSystem();
~BankingSystem();
Account query(int accountId);
void addAccount();//option 1
void deleteAccount();//option 2
void AccountInquiry();//option 3
void saveAccount();//option 4
void loadAccounts();//option 5
private:
std::vector<Account> accounts_;
};
#endif // BANKING_SYSTEM_H
\ifndef银行系统\u H
#定义银行系统
#include//用于允许字符串函数
#包括
类别帐户{
公众:
帐户(int accountNumberValue,int passCode,std::string lastName,
std::字符串名,双平衡);
~Account();
void setFirstName(std::string&);
std::string getFirstName();
void setLastName(std::string&);
std::string getLastName();
void setAccountNumber(int accountNumberValue);
int getAccountNumber();
void setPassCode(int passcode值);
int getPassCode();
无效余额(双倍余额值);
双getBalance();
私人:
std::stringfirstname;
std::字符串lastName;
国际帐户号码;
整数密码;
双平衡;
}; // 末级科目
类银行系统
{
公众:
BankingSystem();
~BankingSystem();
账户查询(int accountId);
void addAccount();//选项1
void deleteCount();//选项2
void AccountInquiry();//选项3
void saveAccount();//选项4
void loadAccounts();//选项5
私人:
std::向量机;
};
#endif//银行系统
正如消息所暗示的,您忘记了一个代码>。类定义应该用后缀代码>。e、 g.类Foo{…}代码>。您还有帐户查询(int accountId)
在银行系统
中重复多次,无效,并且在每个类定义后有两个#endif
一个。类帐户{…};你错过了机会;在测试之前,您不应该编写这么多代码,在要求我们检查之前,您应该将其简化为一个最小的示例。非常感谢大家的帮助。我整天都在做这件事,只是看不出我遗漏了什么。。我真的很感谢大家的帮助。
#ifndef BANKING_SYSTEM_H
#define BANKING_SYSTEM_H
#include <string> // Used to allow string functions
#include <vector>
class Account {
public:
Account( int accountNumberValue, int passCode, std::string lastName,
std::string firstName, double balance);
~Account();
void setFirstName ( std::string & );
std::string getFirstName();
void setLastName( std::string & );
std::string getLastName();
void setAccountNumber( int accountNumberValue );
int getAccountNumber();
void setPassCode( int passCodeValue );
int getPassCode();
void setBalance( double balanceValue );
double getBalance();
private:
std::string firstName;
std::string lastName;
int accountNumber;
int passCode;
double balance;
}; // end class Account
class BankingSystem
{
public:
BankingSystem();
~BankingSystem();
Account query(int accountId);
void addAccount();//option 1
void deleteAccount();//option 2
void AccountInquiry();//option 3
void saveAccount();//option 4
void loadAccounts();//option 5
private:
std::vector<Account> accounts_;
};
#endif // BANKING_SYSTEM_H