Example & Tutorial understanding programming in easy ways.

What is final in C++ ?

Final in C++:
-Sometimes you don't want to allow derived class to override the base class' virtual function.
-C++ 11 allows built-in facility to prevent overriding of virtual function using final specifier.

program:

#include < iostream>
using namespace std;
class Base
{
public:
virtual void myfun() final
{
cout << "myfun() in Base";
}
};
class Derived : public Base
{
void myfun()
{
cout << "myfun() in Derivedn";
}
};
int main()
{
Derived d;
Base &b = d;
b.myfun();
return 0;
}


output-

Give some error




Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!