Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a class that can not be inherited by other classes? [duplicate]

Can anyone tell how to create class so that it can not be inherited by any other classes.

class A {
  public :
          int a;
          int b;
};

class B : class A {
   public :
           int c;
};

in above program i do not want to allow other classes to be inherited by class B

like image 759
ssg Avatar asked Dec 02 '22 12:12

ssg


1 Answers

Mark the class final (since C++11):

class A final {
public :
    int a;
    int b;
};
like image 189
Jarod42 Avatar answered Dec 05 '22 07:12

Jarod42