为什么我得到对Class::Class()的未定义引用
Why am I getting undefined reference to Class::Class()?
error: undefined reference to ' 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是因为我已经提到过这个类了。
事务类不可见。我在同一文件的Product类下面定义了它。我必须把它放在一个单独的头文件中
相关文章:
- VSCode - C++对"CLASS::FUNCTION"的未定义引用
- 对 Class::Class() 和函数在一个文件中的未定义引用? c++
- 在 C++ 中对"Class::function()"错误的未定义引用 [CLion IDE]
- 对"Class::StaticStructMember"的未定义引用
- 对 Class::Class/Function 的未定义引用(OOP 中的初学者)
- 对"typeinfo for <class>"的未定义引用
- 对'vtable for class'的未定义引用
- 共享库中非模板基的模板子类导致未定义的符号类型信息'class'链接错误
- 解决方法:未定义对"class::function"的引用
- C++:对 class::function() 的未定义引用
- 奇怪的错误:未定义对"class::class()"的引用
- 对 class::function 的未定义引用
- Qt 5 C++ 对 Class::function(QString, Qstring, ..) 的未定义引用
- 对[class::function]的未定义引用/对[class]的typeinfo的未定义参考
- 对'Class::Class(function)'的未定义引用
- cpp 未定义对"class::method"的引用
- 对 CLASS::function() 的未定义引用
- C++ 错误:标识符'class name'未定义
- G++ 未定义对 class::function 的引用
- Visual Studio 2013 中的C++ - <Class> 未定义