A vitual function is function which is an inheritable and overridable
function which will support dynamic dispatch. Ideally this is what we
call runtime polymorphism. In a nutshell, the virtual function
provides a target function to be executed, which we have no idea at
the compile time. Suppose you extend a class having a virtual
function, you get the ability to use polymorphism to execute the
function in the derrived class, using a base class pointer.
More read on https://www.geeksforgeeks.org/virtual-functions-and-runtime-polymorphism-in-c-set-1-introduction/
A pure virtual function or pure virtual method is a virtual function
that is required to be implemented by a derived class if the derived
class is not abstract.
A point to note is, if you have a pure virtual function in a class, you cannot instantiate it as an object.
look at the following example
class Base {
public:
virtual string getType() = 0;
}
class Derived : public base {
public:
string getType();
}
string
derived::getType() {
//do necessary stuff <------------------ (1)
}
Base* myBase = new Derived(); // OK
myBase->getType() //this will call the logic at (1).That's in the derived class but not base
Base* myBase2 = new Base();//Error
And for your question, pure virtual function is a declaration. And does not need a definition.
*EDIT You can provide a default implementation but you have to override in the derived classes of this base class with pure virtual function *