Why they are no Virtual Constructors.
-
Hi all, i want to know exactly why there will not be any Virtual Constructors but There exist a Virtual Destructor. Please let me know the exact reason behind this.
Uday kiran
-
Hi all, i want to know exactly why there will not be any Virtual Constructors but There exist a Virtual Destructor. Please let me know the exact reason behind this.
Uday kiran
please search the board and some FAQs, this question has been asked bilions of times
[VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]
-
Hi all, i want to know exactly why there will not be any Virtual Constructors but There exist a Virtual Destructor. Please let me know the exact reason behind this.
Uday kiran
Does the v-table exist at the time the class' constructor is invoked? I think a virtual constructor would actually be pretty pointless since it is used for derived classes. See here for more.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Does the v-table exist at the time the class' constructor is invoked? I think a virtual constructor would actually be pretty pointless since it is used for derived classes. See here for more.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Thanks David, You have give a more valuable information. thank you very much.
Uday kiran
-
Thanks David, You have give a more valuable information. thank you very much.
Uday kiran
-
uday kiran janaswamy wrote:
You have give a more valuable information.
He didn't give "information" to you he gave you a "pointer" to it. Typical C++ nub... not understanding pointers. :-D
led mike
:laugh:
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it."
-
uday kiran janaswamy wrote:
You have give a more valuable information.
He didn't give "information" to you he gave you a "pointer" to it. Typical C++ nub... not understanding pointers. :-D
led mike
I think you misunderstood what he wrote. it should have been something like : You have given me a most valuable information. or something like that.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Hi all, i want to know exactly why there will not be any Virtual Constructors but There exist a Virtual Destructor. Please let me know the exact reason behind this.
Uday kiran
When an object is created you are specifying the exact object type. It is constructed from the inside out so there is no need for a v-constructor. Once an object exists it can be pointed to by a pointer to a parent class type. Yet, the object needs to be destroyed from the outside in. Without a v-destructor destruction would start with the type of the pointer not of the actual object.
...cmk Save the whales - collect the whole set
-
When an object is created you are specifying the exact object type. It is constructed from the inside out so there is no need for a v-constructor. Once an object exists it can be pointed to by a pointer to a parent class type. Yet, the object needs to be destroyed from the outside in. Without a v-destructor destruction would start with the type of the pointer not of the actual object.
...cmk Save the whales - collect the whole set
In Other words, When the First Step of construction takes place, we are constructing the Root Class, which has the V-Table of the Root Class.(No Idea yet of Your Classes' V-Table) If the language allowed you to declare a Virtual constructor, it would be in the V-Table of your final class, and only be available AFTER your class was constructed. Now that would be realy like mustard after the meal. Ofcourse someone could write a compiler which takes account of these things. The language it compiles would no longer be cpp though. The long and short of it is therefore, If you need a Virtual Constructor, you are organising your code wrong. :-O Look at your code and try again. regards
LateNightsInNewry
-
In Other words, When the First Step of construction takes place, we are constructing the Root Class, which has the V-Table of the Root Class.(No Idea yet of Your Classes' V-Table) If the language allowed you to declare a Virtual constructor, it would be in the V-Table of your final class, and only be available AFTER your class was constructed. Now that would be realy like mustard after the meal. Ofcourse someone could write a compiler which takes account of these things. The language it compiles would no longer be cpp though. The long and short of it is therefore, If you need a Virtual Constructor, you are organising your code wrong. :-O Look at your code and try again. regards
LateNightsInNewry
LateNightsInNewry wrote:
The long and short of it is therefore, If you need a Virtual Constructor, you are organising your code wrong. :-O Look at your code and try again.
Even if you need one, C++ is not going to let you have one. That would be a compile time error blunder.
The greater the difficulty, the greater the glory. - Marcus Tullius Cicero