I am new to C++, I coded in Java for an year. The equivalent in C++ for interfaces and abstract classes alike is only abstract classes. Is that supposed to be a handicap while doing factory design? There are many times I want to leave out the defining the methods to the inheriting classes and I want to enforce that.
Share
Java interfaces are best translated as C++ abstract classes. In Java (as far as I know) a interface is merely a subset of an abstract class anyway, except it allows “multiple inheritance” which C++ has in all cases anyway.
The
=0syntax means it is not defined in the interface, but must be defined in classes that fulfill the interface. Also note that if you have any virtual function, you almost always want a virtual destructor as well. C++ will tell you an error if you try to make athing_interfaceby itself, since there’s no implementation functions.It’s not really a handicap, since I can’t think of anything Java can do here that C++ can’t.