Can we have a private virtual method ?
Answer Posted / ganesh mishra
yes... we can have private virtual method and will not give
any compile time/runtime error.but when we derive any class
from it and override the virtual function,then the compiler
will throw a compile time error.
//file name is privatever.cpp
#include <iostream>
using namespace std;
class base
{
virtual void fun()
{
cout <<"base class function"<<endl;
}
};
class derive: public base
{
public:
virtual void fun()
{
cout<<"derived class function"<<endl;
}
};
int main()
{
base *pt;
derive *der = new derive;
pt = der;
pt->fun();
return(0);
}
here is the error
privatever.cpp: In function ‘int main()’:
privatever.cpp:6: error: ‘virtual void base::fun()’ is private
privatever.cpp:27: error: within this context
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is methods in oop?
What is overloading in oop?
hi all..i want to know oops concepts clearly can any1 explain??
Is this job good for future? can do this job post grduate student?
Will I be able to get a picture in D drive to the c++ program? If so, help me out?
What is oops and its features?
What is overloading in oops?
What is object-oriented programming? Webopedia definition
Why is polymorphism needed?
How do you achieve runtime polymorphism?
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
How is polymorphism achieved?
Is abstract thinking intelligence?
Get me an image implementation program.
What are the two different types of polymorphism?