I'm having some trouble attempting to implement the constructors for each class.

I have this constructor for the class Transaction. Is this correct ?

Transaction::Transaction(QString type, QDateTime datetime) : m_Type(type), m_DateTime(datetime)
{ }

AND how do i implement the constructor for the class Deposit ?
Is this correct ? I'm getting the following error (refer to attachment)

Deposit::Deposit(double amount) : Transaction(type,datetime)
{ }

Any help will be appreciated to get me going.
Thanks
Reggie

#ifndef Q1_H
#define Q1_H

class Transaction{
    public:
        Transaction(QString type, QDateTime datetime);
        QString getType() const;
        QString toString() const;
        QDateTime getDateTime() const;
        virtual double computeCost() = 0;
    protected:
        QString m_Type;
        QDateTime m_DateTime;
};



class Deposit : public Transaction{
    public:
        Deposit(double amount);
        QString toString() const;
        double computeCost();
    private:
        double m_Amount;
        static double m_Fee;
};



class Withdrawal : public Transaction{
    public:
        Withdrawal(double amount);
        QString toString() const;
        double computeCost();
    private:
        double m_Amount;
        double m_Percentage;
};


class BalanceEnquiry : public Transaction{
    public:
        BalanceEnquiry(QDate fDate, QDate tDate);
        QString toString() const;
        double computeCost();
    private:
        QDate m_FromDate;
        QDate m_ToDate;
};



class SavingsAccount{
    public:
        SavingsAccount(QString name, QString num);
        ~SavingsAccount();
        void addTransaction(Transaction* t);
        double totalTransactionCost();
        QString frequentTransactionType() const;
        QList<Transaction*> transactionsOnADate(QDate date);
        QString toString() const;
    private:
        QString m_CustomerName;
        QString m_AccountNumber;
        QList<Transaction*> m_TransactionList;
};

#endif // Q1_H

Hi
In the constructor initialization list arguments (type,datetime) passed to base class (transaction) was not declared at the scope of the derived class (Deposit)

Deposit::Deposit(double amount) : Transaction(type,datetime)
{ }

As i can see in your Transaction declaration you should use

protected:
        QString m_Type;
        QDateTime m_DateTime;

instead of type and datetime

Thank you Helmi 1.
After having done that i get the following error message.
"undefined reference to vtable for Deposit"

Any ideas what i'm doing wrong ?

Deposit::Deposit(double amount) : Transaction(m_Type,m_DateTime)
{ }

Try somethinh like this:

class Transaction
{
public:
    Transaction(QString type, QDateTime datetime) : m_Type(type), m_DateTime(datetime) {}
    QString getType() const { return m_Type; }
    QString toString() const { return m_Type + " @ " + m_DateTime; }
    QDateTime getDateTime() const { QDateTime now; return now.get_date_time(); }
    virtual double computeCost() = 0;
protected:
    QString m_Type;
    QDateTime m_DateTime;
} ;

class Deposit : public Transaction{
public:
    // note order beloe ... //
    Deposit(double amount) : Transaction("Deposit", getDateTime() ), m_Amount(amount) {}

    QString toString() const;
    double computeCost();
private:
    double m_Amount;
    static double m_Fee;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.