On 31 Jan 2007 21:51:01 -0800,
wrote:
>I have some code in Java that I need to translate into C++. My Java
>code defines a class hierarchy as follows:
In general, Java's interface definitions can be implemented in C++ as a class
with nothing but pure virtual functions (and a public virtual destructor that
does nothing).
Java:
public interface I
{
public abstract void fn();
}
C++:
class I // Interface
{
public:
virtual void fn() = 0;
virtual ~I() {}
};
Implementing a Java interface is analogous to virtual public inheritance in
C++.
Java:
public class A implements I
{
public void fn() { /* ... */ }
}
C++:
class A: public virtual I
{
public:
virtual void fn() { /* ... */ }
};
I started a thread about the pros and cons of performing this analogous
exercise in C++ about a week ago. Do a search for my name and the topic
"Virtual inheritance and interfaces".
-dr