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