为什么我得到对 Class::Class() 的未定义引用?
Why am I getting undefined reference to Class::Class()?
错误:未定义对`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 作为我已经提到的 class 问题。
交易 class 不可见。我在同一个文件中的 Product class 下面定义了它。我不得不把它放在一个单独的头文件中。
错误:未定义对`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 作为我已经提到的 class 问题。
交易 class 不可见。我在同一个文件中的 Product class 下面定义了它。我不得不把它放在一个单独的头文件中。