What is virtual constructors/destructors?

Answers were Sorted based on User's Feedback



What is virtual constructors/destructors?..

Answer / nk

There is nothing like virtual constructors but we can have
virtual destructors so that the destructor of the correct
object is called.
Ex.

Base *bptr = new derived()

delete bptr; then the destructor of the derived objetc is
called when the base destructor is marked as virtual.

else destructore of base class is called and may lead to
memory leak if we have allocated any new memory.

Is This Answer Correct ?    18 Yes 1 No

What is virtual constructors/destructors?..

Answer / debasish

there is no virtual constructor..coz..virtual thing is in
run time n constructor ic compile time thing.

Is This Answer Correct ?    15 Yes 3 No

What is virtual constructors/destructors?..

Answer / syed abdul gaffur.

CONSTRUCTOR:

Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.

DISTRUCTOR :

If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object

Is This Answer Correct ?    7 Yes 0 No

What is virtual constructors/destructors?..

Answer / khadeer.k

virtual constructors are used when we need to avoid the
copy same. desructor frees the memory with a ~(tilde) symbol

Is This Answer Correct ?    8 Yes 9 No

Post New Answer

More OOPS Interview Questions

What type of loop is a for loop?

0 Answers  


What is methods in oop?

0 Answers  


What is a class and object?

0 Answers  


what is the difference between function template and template of function?explain with example.

2 Answers  


Templates mean

0 Answers  






Program to open a file with First argument

1 Answers   TCS,


Write a program to multiply 3x3 matrics

1 Answers  


who is the founder of c++?

15 Answers   Hexaware, ONGC,


what is use to destroy an object? illustrate.

5 Answers   TCS,


What do you mean by overloading?

0 Answers  


difference between abstraction and encapsulation with progarammatic eg. hi,just recently i went for an interview .The interviewer asked what is the difference between abstraction and encapsulation with programmatic eg. I gave the answer as encapsulation mean hiding the relevant data which is not useful for the user, eg a electric fan .hiding the information how the electricity is converted into machanical energy. abtraction showing only the relevant data to the user eg electric fan. it look ,its color ,it design etc only relevant data. Then the interviewer asked me, give me some programmic eg .I Said Let assume a web form having control like textbox,button etc. The user can view textbox,button etc this is the eg of abstraction and when the user click on the button how he is redirected is not known by the user is the eg of the encapsulation. Am I Correct .was the answer given by me is perfect .now i am planing to go for an another interview should i give the same answer.IF not please suggest me a better answer.with some good eg Please help

1 Answers  


What is debug class?what is trace class? What differences are between them? With examples.

0 Answers  


Categories