Click here to Skip to main content
15,891,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am creating my own UI component in MFC. I derived it from CWnd class and I am going to override OnPaint() method. My question concerns the method Create(), that is inherited from CWnd . I would like to know if it is good to call that from the constructor (perhaps not, because virtual methods shall not be called while creation) or I shall let the client of the class to call the Create() method on his own (which I dont like)...

Thanks for your opinions.

Best regards,
J.K.
Posted

MFC's philosophy is a 2-step creation process, so a separation of constructor and create call. I would just stick with that for reasons of presenting a consistent behavior to other MFC classes.

A second good reason for having the caller call Create is that from a constructor you have limited means of reporting any errors. You can just throw an exception, whereas in a separate Create function you can return a value.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Jun-13 19:43pm    
Good point, a 4.
—SA
nv3 12-Jun-13 1:51am    
Thanks, Sergey.
I'm afraid you should use the Create approach: General Window Creation Sequence[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Jun-13 19:42pm    
Good link, a 5.
—SA
Espen Harlinn 12-Jun-13 15:43pm    
Thank you, Sergey :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900