How to call a non virtual function in the derived class by
using base class pointer
Answer Posted / ak
It's simple.
Since in question it is asked how to call "non virtual
function in derived class" which means in derived class we
need to access non-virtual function using Base Class's pointer.
Note:
In question its no where mentioned that we cannot use
virtual function in Base class.
So in Base class same function can be made virtual and we
can use it through Base's pointer.
See eg. below:
class Base
{
public:
virtual void fun()
{
cout<<"Inside Base's fun";
}
};
class Derived : public Base
{
public:
void fun()
{
cout<<"Inside Derived's fun";
}
};
int main()
{
Base *bp = new Derived;
bp->fun();
getch();
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What is the difference between a mixin and inheritance?
write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).
Why is object oriented programming so hard?
Plese get me a perfect C++ program for railway/airway reservation with all details.
What is the point of oop?
Is react oop?
What are the components of marker interface?
What is abstraction and encapsulation?
What is object in oop?
What are classes oop?
Why polymorphism is used in oops?
There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.
What is overloading in oop?
What is the real time example of encapsulation?
Where You Can Use Interface in your Project