Why is the OO concept interface not represented by a keyword in C++?

Because C++ allows multiple inheritance, and because an interface is an abstract class which has all of it's members also abstract/virtual, C++ does not need it - a class can simply "extend" multiple other classes, any of which may be purely virtual (abstract).

Java and C#, on the other hand do not permit MI, since the designers of those languages felt that MI creates more problems than it solves. But it is still necessary for an object to "be" many things (the OOP is-a relationship), so interfaces provide a mechanism which allows an object to be many things, without inheriting multiple implementations - keeping the baby, but throwing out the bathwater.


It's redundant, since interfaces are represented by having every class member be pure virtual (=0).


Adding an "interface" keyword would add complexity to the implementation without adding any truly useful capability; it would duplicate existing functionality. As others have said, it's just a pure virtual class. Java and C# had to have 'interface' to get a piece of what C++ already had. Philosophically, C++ is designed to enable programmers to write good software, not to prevent programmers from writing bad software. In my experience, the hoopla against MI is way overblown. Idiots misused it, like they misuse everything, and instead of blaming the idiots for being idiots, people blamed the tool.

Tags:

C++

Oop