What's the difference between MFC's Dynamic Creation and C++'s new?

What's the difference between MFC's Dynamic Creation and C++'s new?

Post by Flying Be » Fri, 19 Sep 1997 04:00:00



        Hi,all:
        I am confused with MFC's dynamic creation mechanism.
        why does Microsoft design this? i mean, if someone needs to create
        a object at run-time,he just uses "new" operator provided by C++
        then everything is OK.  
        why bother to use thing like pRuntimeClass->CreateObject()?

        Am i missing some important points?Is there something only can
        be done with dynamic creation and not with C++'s new?

        Thanks for your answers !! :)

--

IDIC--"Infinite Diversity in Infinite Combinations".

 
 
 

What's the difference between MFC's Dynamic Creation and C++'s new?

Post by Alfie Kirkpatric » Wed, 24 Sep 1997 04:00:00


My (limited) understanding is that with CRuntimeClass,
you can create objects when you don't even know the
exact type they are going to be. This is different
from new which always creates a particular class type.

The best example I've found of CRuntimeClass in action
is in serialisation. If you have a list of pointers to
objects with a common base class, how do you make sure
the correct classes are recreated when loading the list
from a serialised file? With MFC, you can use WriteObject
and the CRuntimeClass information is also written so the
correct objects get recreated. I thought it was pretty
clever myself.

Hope it helps.
Alfie.
--
Alfie Kirkpatrick
IMS International



Quote:>    Hi,all:
>    I am confused with MFC's dynamic creation mechanism.
>    why does Microsoft design this? i mean, if someone needs to create
>    a object at run-time,he just uses "new" operator provided by C++
>    then everything is OK.  
>    why bother to use thing like pRuntimeClass->CreateObject()?

>    Am i missing some important points?Is there something only can
>    be done with dynamic creation and not with C++'s new?

>    Thanks for your answers !! :)

> --

> IDIC--"Infinite Diversity in Infinite Combinations".


 
 
 

What's the difference between MFC's Dynamic Creation and C++'s new?

Post by Shawn Fessende » Sun, 28 Sep 1997 04:00:00


Quote:> My (limited) understanding is that with CRuntimeClass,
> you can create objects when you don't even know the
> exact type they are going to be. This is different
> from new which always creates a particular class type.

Apples and oranges. Think of new as a sophisticated malloc. Dynamic
creation is simply using stored type info to instance an object. The two
operations bear hardly any resemblance to each other.
--
Remove '*' to reply by email.

"Geek used to be a four-letter word. Now it is a six-figure one."
 
 
 

1. 'Dynamic' SetWindowRgn(...) in MFC

  I am trying to alter a region I have applied to a window.
  I keep the region in scope until the window is destroyed.
  I call SetWindowRgn(...) once just before the window is displayed.

  I alter the applied region for various  reasons through the life of the
window, and the force a redraw of the window.

  I don't call SetWindowRgn(...) again as this crashes the GDI, I just force
a redraw of my window.
  This seems to work, except for the areas that were visible in the previous
region and are now clipped out by the new region. The windows underneath
aren't redrawn, I am just left with remnants of my window.

  I can't easily keep a list of the all the possible regions and select
between them as there could be too many.

  Has anybody tried similar things and got it working?

  Ed Sayers

2. DDE hot links

3. 'Instance' and 'InstanceCm' subkey difference?

4. Backup network drives

5. What is a 'service', 'process' and the difference?

6. Night walker

7. Difference between 'size' and 'size on disk' in Explorer

8. highlight newly installed programs option not working properly

9. Difference between 'Bad IP' & 'Host Unknown'

10. Difference between 'Users' & 'Administrators'

11. 'CSplitterWnd' and 'Use MFC in a static Library'

12. Computer starts writing '''''''''''''

13. C++'s new versus C's GlobalAlloc/GlobalLock