Associate
I am wanting to implement an interface in C++ like you do in Java.
In java it's very easy, all you need to do is create an interface and then create a variable of that interface, then instantiate it with an implementation of the interface.
But how would you do that in C++.
For example, if you have the class base with the virtual method void print(); in the header file. Then you have a class derived with inherits from base and where you then implement void print();. If you then create a main class where you do something like -
main.h
base something;
main.cpp
something = derived();
something.print();
How would you do that?
In java it's very easy, all you need to do is create an interface and then create a variable of that interface, then instantiate it with an implementation of the interface.
But how would you do that in C++.
For example, if you have the class base with the virtual method void print(); in the header file. Then you have a class derived with inherits from base and where you then implement void print();. If you then create a main class where you do something like -
main.h
base something;
main.cpp
something = derived();
something.print();
How would you do that?