Click here to Skip to main content
15,886,026 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: why no virtual constructor? Pin
Stefan_Lang16-Jul-12 22:07
Stefan_Lang16-Jul-12 22:07 
AnswerRe: why no virtual constructor? PinPopular
jschell16-Jul-12 6:01
jschell16-Jul-12 6:01 
GeneralRe: why no virtual constructor? Pin
Stefan_Lang16-Jul-12 22:08
Stefan_Lang16-Jul-12 22:08 
AnswerRe: why no virtual constructor? Pin
Chris Losinger16-Jul-12 7:02
professionalChris Losinger16-Jul-12 7:02 
AnswerRe: why no virtual constructor? Pin
David Crow16-Jul-12 7:06
David Crow16-Jul-12 7:06 
GeneralRe: why no virtual constructor? Pin
jschell16-Jul-12 10:49
jschell16-Jul-12 10:49 
AnswerRe: why no virtual constructor? Pin
Mattias Högström16-Jul-12 11:34
Mattias Högström16-Jul-12 11:34 
GeneralRe: why no virtual constructor? Pin
Stefan_Lang16-Jul-12 22:29
Stefan_Lang16-Jul-12 22:29 
You started on a good idea, i. e. posing the question 'what if?'. You raised the wrong question though, since initialization is not really a problem: C++ implicitly calls the constructors of its parent classes!

Instead you should have asked this:

What if ...
1. I had a class called Animal
2. two subclasses called cat and mouse
3. a virtual constructor for Animal.
--> what would that constructor create?

There is no answer to this question: in order to decide what subclass to create, you'd need to decide what type the object is of. But to decide the type, you'd need to create the object first! It is a typical hen-and-egg problem. It cannot be solved. Therefore there is no sense in a virtual constructor.

There is a mechanism for methods that do not require an actual instance of an object: static. But you cannot override a static method, exactly because it is not tied to an instance, and therefore there is no way to resolve a virtual call!
GeneralRe: why no virtual constructor? Pin
Mattias Högström17-Jul-12 0:38
Mattias Högström17-Jul-12 0:38 
GeneralRe: why no virtual constructor? Pin
Stefan_Lang17-Jul-12 2:00
Stefan_Lang17-Jul-12 2:00 
GeneralRe: why no virtual constructor? Pin
Mattias Högström17-Jul-12 10:07
Mattias Högström17-Jul-12 10:07 
JokeRe: why no virtual constructor? Pin
Albert Holguin17-Jul-12 12:19
professionalAlbert Holguin17-Jul-12 12:19 
GeneralRe: why no virtual constructor? Pin
jschell20-Jul-12 6:52
jschell20-Jul-12 6:52 
GeneralRe: why no virtual constructor? Pin
Mattias Högström20-Jul-12 7:33
Mattias Högström20-Jul-12 7:33 
GeneralRe: why no virtual constructor? Pin
jschell21-Jul-12 11:33
jschell21-Jul-12 11:33 
GeneralRe: why no virtual constructor? Pin
Mattias Högström21-Jul-12 13:54
Mattias Högström21-Jul-12 13:54 
GeneralRe: why no virtual constructor? Pin
Eugen Podsypalnikov16-Jul-12 23:59
Eugen Podsypalnikov16-Jul-12 23:59 
QuestionHow to add app icon in full color? Pin
includeh1014-Jul-12 15:22
includeh1014-Jul-12 15:22 
AnswerRe: How to add app icon in full color? Pin
«_Superman_»14-Jul-12 17:58
professional«_Superman_»14-Jul-12 17:58 
QuestionMFC CListCtrl FindItem is not working Pin
D.Manivelan13-Jul-12 23:45
D.Manivelan13-Jul-12 23:45 
AnswerRe: MFC CListCtrl FindItem is not working Pin
_Flaviu14-Jul-12 0:06
_Flaviu14-Jul-12 0:06 
GeneralRe: MFC CListCtrl FindItem is not working Pin
D.Manivelan14-Jul-12 1:14
D.Manivelan14-Jul-12 1:14 
GeneralRe: MFC CListCtrl FindItem is not working Pin
_Flaviu14-Jul-12 1:20
_Flaviu14-Jul-12 1:20 
GeneralRe: MFC CListCtrl FindItem is not working Pin
Rolf Kristensen14-Jul-12 21:41
Rolf Kristensen14-Jul-12 21:41 
AnswerRe: MFC CListCtrl FindItem is not working Pin
Richard MacCutchan14-Jul-12 0:17
mveRichard MacCutchan14-Jul-12 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.