Your function is pure virtual, which means the method is virtual and not even implemented in the base class (= 0)
.
So you have to delete the block after it.
It has to be:
virtual price(int Uchrg, int no_of_unt) = 0;
without the { }
.
Virtual means, that classes that inherit from a base class can override the method and called via the base class interface. If a class has a pure virtual method, the class is abstract and this function needs to be overridden by classes that inherit from that base class to be instantiated.
In short:
Virtual:
virtual price(int Uchrg, int no_of_unt)
{
// Implementation
}
Has an implementation is the base class. Sub classes does not need to override, but they can. The class is not abstract and can be instanciated.
Pure virtual:
virtual price(int Uchrg, int no_of_unt) = 0; // No implementation
There is no implementation, the sub classes must override this to be not abstract.
Call a virtual method via base class:
Base* pBase = new Derived;
pBase->fun();
The method is called via the interface of the base class, but it will be the derived class’ method.
0
solved Why is this pure virtual method not compiling? [closed]