I want to create interface in cpp such that is any class implement that class then that class must implement parent class’s functions. if all functions are not implemented then it must shows error.
class parent { // interface class
public :
virtual void display();
}
class base : public parent {
void display(); // this method must be implemented in this class
}
please help me for this type of inheritance in c++.
Use a pure virtual member function:
This makes the class abstract (you can’t make instances of it), and any non-abstract deriving class must implement such functions.
Here’s a Wikipedia link with a more formal definition:
http://en.wikipedia.org/wiki/Virtual_function#Abstract_classes_and_pure_virtual_functions