Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

MFC - IMPLEMENT_DYNCREATE() creates error

stephen-smolley
2,525 Views
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
2 Replies
stephen-smolley
2,525 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
PauloEP
Beginner
2,166 Views

It worked! But I had to modify to:

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

 

0 Kudos
Reply