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

How do you explain polymorphism?

0 Answers  


c++ is a pure object oriented programming or not?

5 Answers   Wipro,


Which is the only operator in C++ which can be overloaded but NOT inherited?

8 Answers  


How many types of access specifier in c# and vb.net?

1 Answers   Infosys,


Write an operator overloading program to write S3+=S2.

2 Answers  


What are the main differences between procedure oriented languages and object oriented languages?

9 Answers   IBM, Infosys, Wipro,


Why do while loop is used?

0 Answers  


What is a unary operator?

5 Answers  


What is virtual class and friend class?

5 Answers   IBS, Intel, Wipro,


What is for loop and its syntax?

0 Answers  


What is the point of oop?

0 Answers  


why reinterpret cast is considered dangerous?

0 Answers   TCS,


Categories