What is virtual constructor paradigm?

Answers were Sorted based on User's Feedback



What is virtual constructor paradigm?..

Answer / malini

There is no concept like Virtual Constructor and where as
Constructor cant be virtual. Constructor is a code which is
responsible for creating a instance of a class and it cant
assigned to any other object by using appending
keyword 'virtual'

Is This Answer Correct ?    8 Yes 0 No

What is virtual constructor paradigm?..

Answer / priyanka kokil

I want to modify the above answer. A constructor cannot be
virtual because at the time when the constructor is invoked
the virtual table would not be available in the memory.
Hence we cannot have a virtual constructor. But we can have
virtual destructor which is defined in Answer #2

Is This Answer Correct ?    5 Yes 0 No

What is virtual constructor paradigm?..

Answer / subhashish sen

Hi Priyanka Kokil,

What ever u have answered its not 100% correct..As we know
for every virtual function in a class one VTABLE is created
internally and constuctor is an entity who intializes this
VTABLE for all virtual functions of a class.For example if
we have a base class and a derived class derived from
it,then 2 VTABLE will be created one for base and one for
derived class.So if you make constructor as virtual then
who will create VTABLE for this constructor.Thats why
constructor can never be virtual.

Thanks!!!!!If u have ny suggession plz reply..

Is This Answer Correct ?    5 Yes 3 No

What is virtual constructor paradigm?..

Answer / priyanka kokil

A virtual destructor is one that is declared as virtual in
the base class and is used to ensure that destructors are
called in the proper order. It is to be remembered that
destructors are called in the reverse order of inheritance.
If a base class pointer points to a derived class object
and we some time later use the delete operator to delete
the object, then the derived class destructor is not called.

Is This Answer Correct ?    2 Yes 2 No

What is virtual constructor paradigm?..

Answer / priyanka kokil

Hi Subhashish Sen,

Thanks for your response and adding more details to my
answer.

Thanks

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More C++ General Interview Questions

What and all can a compiler provides by default?

3 Answers   Accenture, HP,


What are raw sockets, where they are efficient?

2 Answers   Symphony,


What are exceptions c++?

0 Answers  


declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator

0 Answers  


Keyword mean in declaration?

0 Answers  






When should I use unitbuf flag?

0 Answers  


What is the difference between map and hashmap in c++?

0 Answers  


template<class T, class X> class Obj { T my_t; X my_x; public: Obj(T t, X x) : my_t(t), my_x(x) { } }; Referring to the sample code above, which one of the following is a valid conversion operator for the type T? a) T operator T () { return my_t; } b) T operator(T) const { return my_t; } c) operator(T) { return my_t; } d) T operator T (const Obj &obj) { return obj.my_t; } e) operator T () const { return my_t; }

1 Answers   Quark,


How can you say that a template is better than a base class?

0 Answers  


If I is an integer variable, which is faster ++i or i++?

0 Answers  


If a header file is included twice by mistake in the program, will it give any error?

0 Answers  


What is the best c++ compiler for windows 10?

0 Answers  


Categories