How to inherit from multiple CWindowImpl-derived classes

Viewed 76

Is it possible to create a class that derives from two or more CWindowImpl-derived classes? Maybe with virtual inheritance? I was trying to do something like this, in order to take advantage of CHAIN_MSG_MAP:

class CClassOne : public virtual CWindowImpl<CClassOne>
{
public:

BEGIN_MSG_MAP(CClassOne)
    // ...
END_MSG_MAP()

}

class CClassTwo : public virtual CWindowImpl<CClassTwo>
{
public:

BEGIN_MSG_MAP(CClassTwo)
    // ...
END_MSG_MAP()

}

class CClassThree : public CClassOne, public CClassTwo
{
public:

BEGIN_MSG_MAP(CClassThree)
    CHAIN_MSG_MAP(CClassOne)
    CHAIN_MSG_MAP(CClassTwo)
END_MSG_MAP()

}

But when I instantiate CClassThree and try to call SubclassWindow, I get an ambiguous-access compilation error. So does anybody know how to do this?

2 Answers

You don't need to inherit from 2+ CWindowImpl bases (and it does not make much sense overall too). Instead, as you have more choices for your message map in Message Map Macros (ATL), you would prefer to have separate classes with message map referencing them via CHAIN_MSG_MAP_MEMBER or have a composite control with chaining to multiple members, for example (depending on relation between your windows, whether they are peers or parent/child ones).

Or you can use c->CClassOne::Create(); to tell compiler which Create() you want to call.

Related