0

Is there any way to make a class that can not be inherit in C++ like java. If yes How to do that?

Sai Ram
  • 225
  • 2
  • 11

2 Answers2

6

Use the final keyword:

class imma_leaf final
{
    // Stuff...
};
defube
  • 2,355
  • 1
  • 21
  • 30
3

Try to read this article might be helpful.

http://www.codeproject.com/Articles/4444/A-non-inheritable-class

From the article:

template <typename T>
class MakeFinal
{
private:
    ~MakeFinal() { };
    friend T;
};

Inherit from it:

class FinalClass : virtual public MakeFinal<FinalClass>
{ }
Blacktempel
  • 3,817
  • 3
  • 27
  • 50
bhadram
  • 684
  • 8
  • 21