0
我收到虛擬表錯誤,但無法檢測到代碼中的任何錯誤。有人能給我一個正確的方向嗎?對不起,荷蘭語術語,希望它不是一個問題。未定義的引用到Qt中的vtable
#ifndef LIJST_H
#define LIJST_H
#include "product.h"
#include <list>
typedef list<Product*> lijst;
#endif // LIJST_H
// Methode
#ifndef METHODE_H
#define METHODE_H
#include "lijst.h"
class Methode
{
public:
Methode() {}
virtual ~Methode() {}
virtual double run(lijst *items);
};
#endif // METHODE_H
// Productmethode
#ifndef PRODUCTMETHODE_H
#define PRODUCTMETHODE_H
#include "methode.h"
class ProductMethode : public Methode
{
private:
map<string,double> kortingsTabel;
public:
ProductMethode() {}
void addKorting(string naam, double korting);
double run(lijst *items);
};
// Main
#include <QCoreApplication>
#include "factuur.h"
#include "product.h"
#include "globalemethode.h"
#include "productmethode.h"
#include "drempelmethode.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
GlobaleMethode G (0.1);
ProductMethode P;
P.addKorting ("Melk", 0.1);
P.addKorting ("Boter", 0.05);
Factuur F (&G);
F.addProduct (new Product ("Melk", 0.75));
F.addProduct (new Product ("Kaas", 5));
F.addProduct (new Product ("Boter", 1.7));
cout << F.totaal () << endl;
F.setMethode (&P);
cout << F.totaal ();
return a.exec();
}
我打算爲純虛函數,這顯然需要被定義爲 虛擬雙運行(lijst *項目)= 0; 。另外,我確定了ProductMethode中的run方法,但是我忘記了顯示cpp內容。謝謝您的幫助! :) – RobotRock 2013-03-27 11:03:33