Question based on c++ that every programmer must know..
Question 1) What is use of default constructor ?
Answer :-
Default constructor have a initialization code to connect vvptr to VTABLE. This is the one of the reason that the constructor can not be declared as virtual.
Default constructor have a initialization code to connect vvptr to VTABLE. This is the one of the reason that the constructor can not be declared as virtual.
Question 2) What is the size of an object?
Answer:-
If we set virtual function in our class then the size of obj is size if data member + 2 bytes for vvptr (By default).
If we set virtual function in our class then the size of obj is size if data member + 2 bytes for vvptr (By default).
Question 3) why constructor can not be declared as virtual ?
Answer:-
As I told you in answer no. 3 that constructor have a initialization code to connect vvptr to VTABLE. If we create constructor in our class as virtual then c++ generates syntax error because according to the rule of c++ only constructor are able to have a code of initialization and no other function keep this code. That's a reason that constructor can not be declared as virtual.
As I told you in answer no. 3 that constructor have a initialization code to connect vvptr to VTABLE. If we create constructor in our class as virtual then c++ generates syntax error because according to the rule of c++ only constructor are able to have a code of initialization and no other function keep this code. That's a reason that constructor can not be declared as virtual.
Question 4) why late binding is slow?
Answer :-
Because when our program doing late binding firstly it reaches to the object that was pointed then it goes to VATBLE and searching of an function so It have done in 3 steps before show the body of member function.
Because when our program doing late binding firstly it reaches to the object that was pointed then it goes to VATBLE and searching of an function so It have done in 3 steps before show the body of member function.
Comments
Post a Comment