我正在通过继承创建一个名为 AccountList 的 Account* 类型的自定义 QList。
我的 AccountList 接口声明如下:
class Client
{
public:
Client(QString firstName, QString lastName, QString address1, QString address2, QString postalCode);
QString toString();
private:
QString m_FirstName;
QString m_LastName;
QString m_Address1;
QString m_Address2;
QString m_PostalCode;
};
class Account
{
public:
Account(unsigned acctNum, double balance, const Client owner);
unsigned getAcctNum();
double getBalance();
Client getOwner();
virtual ~Account();
private:
unsigned m_AcctNum;
double m_Balance;
Client m_Owner;
};
class AccountList : public QList<Account*>
{
public:
QString toString() const;
Account* findAccount(unsigned accNum) const;
bool addAccount(const Account* acc) const;
bool removeAccount(unsigned accNum) const;
};
我在实现 AccountList 时遇到问题,例如 findAccount 方法。
Account* AccountList::findAccount(unsigned accNum) const
{
Account foundAccount;
foreach(Account* acc, this)
{
if (acc->getAcctNum() == accNum)
{
foundAccount = acc;
break;
}
}
return foundAccount;
}
希望上述方法能让您了解我要完成的工作。看起来很简单而且很直接,但我无法让它工作。Qt Creator 编译器在编译时给了我各种奇怪的错误。
任何帮助,将不胜感激。