Given below classes which of the following are the possible row entries in vtable of D2 class? [code] class Base { public: virtual

Daniel William

New member
Given below classes which of the following are the possible row entries in vtable of D2 class?
Code:
class Base
{
    public:
    virtual void function1() {};
    virtual void function2() {};
};
class D1: public Base
{
    public:
    virtual void function1() {};
};
class D2: public Base
{
    public:
    virtual void function2() {};
};
A. Base::function1() and Base::function2()
B. D2::function1() and Base::function2()
C. Base::function1() and D2::function2()
D. D2::function1() and D2::function2()
 
Answer: c
Explanation: In this program as D2 class is inherited from Base class it inherits both the virtual function of Base class but as the class has not overriden the function1() therefore the Base class definition of function1() will be followed. Therefore the class will have 2 entries corresponding to each function as Base::function1() because it is not defined in Class D2 and D2::function2() because function2() is defined in Class D2.
 

Tìm kiếm

Back
Top