In c++ there is only virtual destructors, no constructors. Why?
Answer Posted / uma sankar pradhan
constructors are invoked at the time of object creation.
The v-table for virtual function mechanism is not
intialised properly during the constructor invocation.
So constructors cannot be virtual
But,destructors can be virtual.Because the V-table is
properly initialised at the time of object creation.
So the v-table is available for the destructors.
Destructors can be made pure virtual also.But unlike other
member functions,it must be redfined outside the class.
| Is This Answer Correct ? | 57 Yes | 22 No |
Post New Answer View All Answers
Can private class be inherited?
What is meant by oops concept?
What is oops and why we use oops?
What is inheritance in simple words?
Can abstract class have normal methods?
What is object and class in oops?
What is an example of genetic polymorphism?
What is this pointer in oop?
What are the three parts of a simple empty class?
Why it is called runtime polymorphism?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
What is solid in oops?
What is the full form of oops?
Advantage and disadvantage of routing in telecom sector
Why do we need polymorphism in c#?