July 13, 2001 tools

ATL Composition

July 13, 2001

I’ve developed a set of macros to support implementing interfaces using nested composition in ATL (the one common way of implementing interfaces they neglected). The benefit of composition is that it is easy to implement multiple interfaces with methods with the same name but that require different behavior, e.g.

interface IArtist : IUnknown {
     HRESULT Draw();
}

interface ICowboy : IUnknown {
     HRESULT Draw();
}

The benefit of this particular implementation is that it has no object size overhead. Interfaces implemented using nested composition have no greater overhead than using multiple-inheritance. Feel free to download atlcompose.h for your own use.