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 abstraction example?
What is oops and why we use oops?
What does sksksk mean in text slang?
Templates mean
write a programe to calculate the simple intrest and compund intrest using by function overlading
What is overriding in oops?
How can you overcome the diamond problem in inheritance?
What is interface in oop?
What is oops?what is its use in software engineering?
Can a destructor be called directly?
Can we define a class within the interface?
what type of questions
What is polymorphism and types?
Can private class be inherited?
What is methods in oop?