Explain calling an object's member function(declared
virtual)from its constructor?

Answer Posted / deepak

It will depend on when pointer to vtable is initialised.
generally if constructor is already defined compiler insert
code to initialise virtual table pointer as first statement
inside defined constructor. If vptr is initialised before
calling virtual function then it will be invoked, if vptr is
not initialised then it can crash.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are pointer-to-members? Explain.

835


If a function doesn’t return a value, how do you declare the function?

833


Differentiate between a pointer and a reference with respect to c++.

980


What is binary search in c++?

815


What is a virtual destructor? Explain the use of it?

773


Write a note about the virtual member function?

824


What is the history of c++?

759


Which ide is best for c++?

783


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

937


What is the difference between function overloading and operator overloading?

805


How much maximum can you allocate in a single call to malloc()?

886


What is array in c++ example?

868


Explain container class.

972


Can we use pointers in c++?

827


What is virtual base class uses?

949