0
錯誤:未定義參考`事務::交易(QString的,QDATE,整型,雙)」爲什麼我得到對Class :: Class()的undefined引用?
從頭文件提取物:
#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,因爲我已經提到過這個類。
「交易」在哪裏定義/實施/鏈接? – ilent2
我想通了,Transaction類對實現是不可見的。 – Morgs
我已經包含缺少的部分 – Morgs