【发布时间】:2021-09-21 04:17:06
【问题描述】:
#include <iostream>
using namespace std;
#include<vector>
#include "CustomerAccount.h"
vector<CustomerAccount>system;
void CreateAccount(vector<CustomerAccount>&system) {
string name;
string email;
int pass;
int phone;
cout << "Pease fill your information : " << endl;
cout << "Please enter your name : ";
cin >> name;
cout << "Please enter your Email : ";
cin >> email;
cout << "Please enter the Password : ";
cin >> pass;
cout << "Please enter your phone number : ";
cin >> phone;
system.push_back(CustomerAccount(name, email, pass, phone));
}
void customer() {
cout << "Choose one : " << endl;
cout << " 1)Login to an existing account " << endl;
cout << " 2)Create a new customer account " << endl;
int MainNum{ 0 };
cin >> MainNum;
if (MainNum == 1)
cout << "k";
else if (MainNum == 2)
CreateAccount(system);
}
This is normal text
嗨, 我想做一个小型餐厅系统程序,程序会询问用户他是管理员还是顾客。 如果他是客户,程序会询问用户是否要创建新帐户。 所以我添加了客户账户类,然后我制作了一个客户账户类的向量(系统),并将向量设为全局。 Create Account 函数将在每次调用该函数时将一个新对象推回 Customer 帐户类。 问题是当我使用系统向量作为函数创建帐户的参数时出现错误,我不知道为什么?
感谢您阅读我的问题
【问题讨论】:
-
当
system完全能够访问这个全局声明的向量时,为什么还需要将它传递给CreateAccount? -
这就是重点,如果没有通过就会出错
标签: c++ function class vector global