c++ "interface"-like classes similar to Java?

Posted by William the Coderer on Stack Overflow See other posts from Stack Overflow or by William the Coderer
Published on 2011-11-20T05:51:46Z Indexed on 2012/10/30 23:01 UTC
Read the original article Hit count: 218

Filed under:
|
|
|

In Java, you can define an interface as a class with no actual code implementation, but only to define the methods that a class must implement. Those types can be passed as parameters to methods and returned from methods. In C++, a pure virtual class can't be used as a parameter or return type, from what I can tell. Any way to mimic Java's interface classes?

I have a string class in C++, and several subclasses for different encodings (like UTFxxx, ISOxxx, etc) that derive from the base string class. However, since there are so many different encodings, the base class has no meaningful implementation. But it would serve well as an interface if I could handle it as its own object and calls to that object would call on the correct subclass it was inherited to.

© Stack Overflow or respective owner

Related posts about java

Related posts about c++