Click here to Skip to main content
15,911,891 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
CodeVarma1-Aug-06 4:40
CodeVarma1-Aug-06 4:40 
AnswerRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
toxcct1-Aug-06 4:45
toxcct1-Aug-06 4:45 
GeneralRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
Zac Howland1-Aug-06 4:55
Zac Howland1-Aug-06 4:55 
GeneralRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
toxcct1-Aug-06 4:59
toxcct1-Aug-06 4:59 
GeneralRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
Zac Howland1-Aug-06 5:11
Zac Howland1-Aug-06 5:11 
AnswerRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
Warren Stevens1-Aug-06 5:13
Warren Stevens1-Aug-06 5:13 
GeneralRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
toxcct1-Aug-06 5:19
toxcct1-Aug-06 5:19 
GeneralRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
Zac Howland1-Aug-06 5:23
Zac Howland1-Aug-06 5:23 
Warren D Stevens wrote:
I've always thought of this as a defect in C++, and yet another reason for people to say (rightly in this case) that C++ is too complex.

For legacy-code reasons it's probably too late now, but it really should have been an error if you 1) add a virtual function 2) write a destructor and not make it virtual.


I've never really had a problem with this (and I have always failed to see why others have a problem with it). If you declare a function virtual in your class, make your destructor virtual as well. If you have no virtual functions, no need to declare your destructor virtual. I can't remember if Microsoft's compiler does this, but I do know that Intel's and GNU both give you a warning (when you have your warning level set to the highest setting) if you have a class with a virtual member function and no virtual destructor.

It should not be an error because it is valid (as far as the standard is concerned), but it is bad practice since it causes lots of bugs. If you made this into an error, you would have to do the same for things like using new without a corresponding delete.

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

AnswerRe: Sir, Why Virtual Constructor doesn't exist ? Whereas we have virtual Destructor. Pin
David Crow1-Aug-06 4:56
David Crow1-Aug-06 4:56 
QuestionTab Control using 'CTabCtrl'? Pin
Andy Rama1-Aug-06 4:39
Andy Rama1-Aug-06 4:39 
AnswerRe: Tab Control using 'CTabCtrl'? Pin
Hamid_RT1-Aug-06 4:53
Hamid_RT1-Aug-06 4:53 
GeneralRe: Tab Control using 'CTabCtrl'? Pin
Andy Rama1-Aug-06 20:32
Andy Rama1-Aug-06 20:32 
GeneralRe: Tab Control using 'CTabCtrl'? Pin
Hamid_RT2-Aug-06 9:29
Hamid_RT2-Aug-06 9:29 
GeneralRe: Tab Control using 'CTabCtrl'? Pin
Andy Rama2-Aug-06 21:04
Andy Rama2-Aug-06 21:04 
GeneralRe: Tab Control using 'CTabCtrl'? Pin
Hamid_RT2-Aug-06 22:01
Hamid_RT2-Aug-06 22:01 
GeneralRe: Tab Control using 'CTabCtrl'? Pin
Andy Rama2-Aug-06 23:11
Andy Rama2-Aug-06 23:11 
GeneralRe: Tab Control using 'CTabCtrl'? Pin
Hamid_RT3-Aug-06 0:52
Hamid_RT3-Aug-06 0:52 
Questionhow to convert a word file to text file Pin
georgekjolly1-Aug-06 4:38
georgekjolly1-Aug-06 4:38 
AnswerRe: how to convert a word file to text file Pin
toxcct1-Aug-06 4:39
toxcct1-Aug-06 4:39 
AnswerRe: how to convert a word file to text file Pin
David Crow1-Aug-06 4:51
David Crow1-Aug-06 4:51 
QuestionGet Current Logged on User Pin
Programm3r1-Aug-06 4:33
Programm3r1-Aug-06 4:33 
QuestionRe: Get Current Logged on User Pin
David Crow1-Aug-06 4:51
David Crow1-Aug-06 4:51 
AnswerRe: Get Current Logged on User Pin
Programm3r1-Aug-06 5:07
Programm3r1-Aug-06 5:07 
QuestionCButton with BS_OWNDERDRAW Pin
YaronNir1-Aug-06 4:17
YaronNir1-Aug-06 4:17 
AnswerRe: CButton with BS_OWNDERDRAW Pin
Hamid_RT1-Aug-06 4:48
Hamid_RT1-Aug-06 4:48 

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.