Is the definition/declaration model all that important?

Started by
19 comments, last by Sc4Freak 16 years, 2 months ago
Quote:Original post by ChaosEngine
Quote:Original post by Zahlman

1) Simply compile your code, then erase the private members from the header. Ship the modified header and the object file. This assumes that your intent is to provide a closed-source library.


Are you sure that will work? I thought client code needed to know the size of an object to instantiate it on the stack. If you do this, won't you get stack corruption? Please correct me if I'm wrong.

A better way (IMHO) is to provide an abstract class (and factory method) as an interface and derive the "real" class from that. Only ship the interface header.

That's basically what I did. But when it came to inheritance between interfaces, it means that you have to deal with multiple and virtual inheritance. For example, let's say there are two kinds of textures. ITexture and IDynamicTexture, and IDynamicTexture inherits from ITexture (since it "is-a" texture).

In the implementation, the CDynamicTexture_Impl class (or whatever you want to call it) will have to inherit from IDynamicTexture (so that it gets the IDynamicTexture and ITexture interfaces), and will also have to inherit from CTexture_Impl, so that it doesn't have to reimplement the ITexture interface. This is multiple inheritance, and the dreaded diamond, which you'll have to use virtual inheritance to solve.

This was the source of my problems in this thread. Now I'm redesigning my system so that it doesn't use this polymorphic pimpl approach.
NextWar: The Quest for Earth available now for Windows Phone 7.

This topic is closed to new replies.

Advertisement