gpt4 book ai didi

c++ - 指针覆盖旧指针

转载 作者:行者123 更新时间:2023-11-28 03:27:25 29 4
gpt4 key购买 nike

<分区>

我被赋予了这项任务,并且在信息被新数据替换方面遇到了很多麻烦。创建新客户时,他们必须创建一个新的基本帐户。这工作正常,但因为我试图允许拥有多种类型帐户的客户,每个帐户都有自己的规则,例如学生/当前,每个帐户都包含自己的值。

出于某种原因,我的帐户的 Money 值变为当前设置的任何值,并且出于某种原因,甚至不同客户的每个帐户都共享其中的值。因此,如果 account1 有 200 英镑,则创建 account2 时有 300 英镑。 account1 将被设置为 300 英镑。

客户.h

Customer(std::string sFirstName, std::string sLastName, 
std::string sAddressLnA,
std::string sAddressLnB,
std::string sCity,
std::string sCounty,
std::string sPostcode,
AccountManager* bankAccount);

AccountManager* getAccount(void);

//outside class
std::ostream& operator << (std::ostream& output, Customer& customer);

客户.cpp

//Part of a method but i've shrunk it down
AccountManager account(H);
AccountManager accRef = account; //This the issue?
Customer c(A, B, C, D, E, F, G, &accRef);
customerList.insert(c);
showPersonDetails();

//Output
ostream& operator << (ostream& output, Customer& customer)
{
output << customer.getFirstName() << " " << customer.getLastName() << endl
<< customer.getaddressLnA() << endl
<< customer.getaddressLnB() << endl
<< customer.getcity() << endl
<< customer.getcounty() << endl
<< customer.getpostcode() << endl
<< (*customer.getAccount()) << endl;
return output;

AccountManager.h

class AccountManager
{
private:
double money;
public:
AccountManager(double amount);
~AccountManager(void);
double getMoney();

};

//Print
std::ostream& operator << (std::ostream& output, AccountManager& accountManager);

账户管理器.cpp

using namespace std;

AccountManager::AccountManager(double amount)
{
money = amount;
}

AccountManager::~AccountManager()
{
}

double AccountManager::getMoney()
{
return money;
}

ostream& operator << (ostream& output, AccountManager& accountManager)
{
//Type of account
output << "Account Money: " << accountManager.getMoney() << endl;
return output;
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com