Apr 20, 2009

Using interface in C++

Yesterday I found that this article has some problem:
http://www.codeguru.com/cpp/cpp/cpp_mfc/oop/article.php/c9989

By its nature interface brings multi-inheritance and it can cause "diamond problem".

In order to solve this problem you have to make sure the "implements" always use "public virtual" rather than just "public". See virtual inheritance.

My implementation is here:
#define IMPLEMENTS( INTERFACE_CLASS_NAME ) public virtual INTERFACE_CLASS_NAME

#define EXTENDS_INTERFACE( INTERFACE_CLASS_NAME ) public virtual INTERFACE_CLASS_NAME
The virtual destructor problem is less important because compiler will notice the programmer when a class has some virtual method without a virtual destructor.

No comments: