我希望此函数使用for循环来遍历我的两个向量(结构体),将最内层结构中每个对象的平衡添加到变量“银行存款余额”。C++通过构造向量循环(包含更多的结构向量)
我不确定如何正确地循环通过此系统来实现此目的。我想我的语法有问题,我试图在结构中调用该向量。
typedef struct account
{
string transactionLog;
float balance;
string *pOwner;
int accountNumber;
string label;
};
typedef account* pAccount;
typedef struct user
{
string testUsername;
string customerName;
string testPassword;
bool isCustomer;
bool isTeller;
bool isManager;
user(string username, string testpassword, string customerName, bool iscustomer, bool isteller, bool ismanager)
: testUsername(username), testPassword(testpassword), customerName(customerName), isCustomer(iscustomer),
isTeller(isteller), isManager(ismanager) {}
typedef vector<pAccount> Accounts;
};
typedef user* pUser;
typedef vector<pUser> userVector;
userVector users;
int vectorPos;
double checkBankBalance()
{
double bankBalance;
for (auto &item : users)
{
for (auto &item : users[item].Accounts)
{
bankBalance = bankBalance + item->balance;
}
}
return 0;
}
我真的不知道如何格式化第二个循环。任何提示将不胜感激,我已经尝试了我能想到的所有事情的组合,以及我在网上看到的所有内容。
为什么要在向量中存储指针?你只是把RAII扔出窗外... – Borgleader