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
  • 245
  • 2
  • 11

2 Answers2

6

Use the final keyword:

class imma_leaf final
{
    // Stuff...
};
defube
  • 2,395
  • 1
  • 22
  • 34
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,935
  • 3
  • 29
  • 53
bhadram
  • 714
  • 2
  • 8
  • 22