What is virtual constructors/destructors?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
what is the difference between virtual function and destoctor?
Have you ever interfaced with a database?
what is different between oops and c++
What is overriding in oops?
State what is encapsulation and friend function?
What is memory leak and memory corruption?
what is multi level inheritance give n example ?
13 Answers HDFC, Hulas Steel, Ness Technologies,
What is debug class?what is trace class? What differences are between them? With examples.
What is operator overloading? Give Example
11 Answers CTS, IBM, TCS,
You attempt to query the data base with this command: SELECT name, salary FROM employee WHERE salary=(SELECT salary FROM employee WHERE last name='Wagner' OR dept no=233) Choose most appropriate option from the following: 1)Sub-queries are not allowed in the where clause. 2)a multiple row sub-query used with a single row comparison operator. 3)a single row query is used with a multiple row comparison operator.
how to create thread in java?
17 Answers IBM, Infosys, Wipro,
suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?