I have an abstract base class and its derived class, although I implemented the pure functions in the cpp file of the derived class, when I try to create an object of the derived I still get an error that says that the derived class is an abstract!! Base:
class Base {
protected:
string name;
int quantity;
double price;
public:
c'tor....
virtual ~Base(){}
virtual void buy(int num) = 0;
};
Derived:
#include "Base.h"
class Derived : public Base{
protected:
double percentage;
public:
c'tor...
virtual ~Derived() {}
virtual void buy(int num);
};
Derived.cpp:
#include "Derived.h"
void Derived::buy(int num){
//implementation
}
main.cpp:
#include "Base.h"
#include "Derived.h"
int main() {
Derived d;
//...
}
Error:
1 IntelliSense: object of abstract class type "Derived" is not allowed:
pure virtual function "Base::buy" has no overrider c:UsersaubDocumentsVisual Studio 2013ProjectsProject22Project22main.cpp 10
Aucun commentaire:
Enregistrer un commentaire