Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
32 Views

MFC - IMPLEMENT_DYNCREATE() creates error

Hey there,

I'm trying to create a class that inherits from two other classes. Both these two MFC classes also inherit from a common type:

class c1 : public CWnd { ... };
class c2 :
public CWnd { ... };

class c3 :
public c1, public c2 { ... DECLARE_DYNCREATE(c3) ... };

...

IMPLEMENT_DYNCREATE(c3, c1) // error C2594: 'return' : ambiguous conversions from 'c3 *' to 'CObject *'

IMPLEMENT_DYNCREATE(c3, CWnd) // ALSO error C2594: 'return' : ambiguous conversions from 'c3 *' to 'CObject *'

I looked over IMPLEMENT_DYNCREATE() but couldn't understand what it meant or how to fix it.
I will try experimenting with different ways to fix this in the mean time.
Thanks in advance for any help.

-Steve
0 Kudos
1 Reply
Highlighted
32 Views

Fixed.

Replace IMPLEMENT_DYNCREATE with IMPLEMENT_DYNCREATE_REINTERPRET and define the following:

#define IMPLEMENT_DYNCREATE_REINTERPRET(class_name, base_class_name) \
CObject* PASCAL class_name::CreateObject() \
{ return reinterpret_cast(new class_name); } \
IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, \
class_name::CreateObject, NULL)


I feel kind of dumb that the solution seems to be this simple. At least someone else can benefit from this potentially.
Thanks anyway!

-Steve
0 Kudos