为什么我得到对Class :: Class()的未定义引用?

时间:2015-09-12 11:19:54

标签: c++ undefined-reference

错误:未定义引用`Transaction :: Transaction(QString,QDate,int,double)'

从头文件中提取:

#include <Transaction.h>

class Product
{
public:
    virtual ~Product();
    void sell(int n);
    void restock(int n);
    void setProductCode(QString c);

    QString getSupplierCode() const;
    QString getProductCode() const;
    QList<Transaction> getTransactions();

    QString toString();
    void removeAll();
    bool isExpired() const;

protected:
    Product(QString name, int num, double seprice, double suprice, QString sc);
    Product(QStringList& prodlist);

private:
    QString m_Name;
    int m_NoOfItems;
    QString m_ProductCode;
    double m_SellingPrice;
    double m_SupplierPrice;
    QString m_SupplierCode;
    QList<Transaction> m_Transaction;
};

实施档案:

//Sell a product
void Product::sell(int n)
{
    if(m_NoOfItems == 0)
  {
    qDebug() << "Out of stock";
  }
  else if(n < m_NoOfItems)
    {
        m_NoOfItems = m_NoOfItems -n;
        m_Transaction.append(Transaction("Sale", QDate::currentDate(),n, m_SellingPrice));
    }
    else qDebug() << "Not enough items in stock";
}

//Restock a product
void Product::restock(int n)
{
    m_NoOfItems = m_NoOfItems +n;
    m_Transaction.append(Transaction("Purchase", QDate::currentDate(),n, `m_SupplierPrice));`
}

Transaction.h

#ifndef TRANSACTION_H
#define TRANSACTION_H

#include <QString>
#include <QDate>

//begining of Transaction Class
class Transaction
{
public:
  Transaction(QString type, QDate date, int num, double price );
  QString toString() const;

private:
  QString m_Type;
  QDate m_Date;
  int m_NoOfItems;
  double m_PricePerItem;

};
//end of Transaction class
#endif // TRANSACTION_H

我正在获得对Transaction::Transaction(QString, QDate, int, double)的未定义引用。它应该如上所述。我已经把class :: class放了,因为我已经提到了这个类了。

1 个答案:

答案 0 :(得分:-1)

交易类不可见。我在同一个文件中的Product类下面定义了它。我不得不把它放在一个单独的头文件中。