C++ C++;QList继承自定义方法问题

C++ C++;QList继承自定义方法问题,c++,inheritance,qlist,C++,Inheritance,Qlist,我正在通过继承创建Account*类型的自定义QList,称为AccountList 我对AccountList的接口声明如下: class Client { public: Client(QString firstName, QString lastName, QString address1, QString address2, QString postalCode); QString toString(); private:

我正在通过继承创建Account*类型的自定义QList,称为AccountList

我对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;
};
希望以上的方法能让你了解我的目标。看起来很简单,但我不能让它工作。Qt Creator编译器在编译时给了我各种奇怪的错误


<> P>FoeCH不是C++ C++中的一个有效的C++构造,即使它不采用该格式。对每一个都使用一个整数循环或std::for_。另外,你真的,真的不应该有账户*,你应该使用某种形式的智能指针。最后,您声明了方法const,这使您继承的QList(为什么不将其作为成员变量?)成为const,这使Account*您希望返回const,但您尝试只返回一个非const。哎呀。

foundAccount应该是指针。 账户*foundAccount; 这将消除您的一些错误。

尝试使用以下方法:

foreach ( Account* account, *this )
{
}

没有准备好Qt安装来测试它,但我很确定您忘记了派生类(AccountList)中的宏
Q_对象


也看到这个问题:

在Qt+C++框架中,Furach是一个有效的构造。我甚至在不使用foreach的情况下尝试了这一点,并选择了迭代器,但有相同的区别。QList是Account*指针列表的唯一原因是因为这是我的作业要求的。我真正需要知道的是如何遍历这个列表,以便根据帐号从列表中返回Account对象。
foreach ( Account* account, *this )
{
}
class myClass : public SomeQtClass
{
    Q_OBJECT
    public:
    // ...
}