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


Please Help Members By Posting Answers For Below Questions

What is abstraction example?

624


What is oops and why we use oops?

573


What does sksksk mean in text slang?

1537


Templates mean

1590


write a programe to calculate the simple intrest and compund intrest using by function overlading

1670






What is overriding in oops?

606


How can you overcome the diamond problem in inheritance?

769


What is interface in oop?

664


What is oops?what is its use in software engineering?

557


Can a destructor be called directly?

603


Can we define a class within the interface?

555


what type of questions

1697


What is polymorphism and types?

602


Can private class be inherited?

619


What is methods in oop?

544