How to make a class from which you can not inherit?

    3 answers 3

    class бесплодный final { }; class лжесын : public бесплодный { }; 

    error C3246: "false": you cannot inherit from "fruitless", since the declaration was as "final"

    • in c ++ 98/03 final was a gcc extension, in c ++ 11 it was added to the standard. - Dith
    • Are there alternatives to final c ++ 98/03? - gecube
    • Do I need the compiler to print an error? The only thing that comes to mind is to put the constructor in private. - manking
    • @gecube Through virtual inheritance you can - see stackoverflow.com/questions/4712992/… - Costantino Rupert

    In C ++, such a thing (final) is not needed two times.

    • Explain more about what they mean. - Cerbo

    In C ++ 2003 you can apply such a focus.

     class Final { private: friend class A; Final() {} }; class A : public virtual Final { public: A() {} }; class B: public A { }; // При попытке создать экземпляр класса B возникнет ошибка компиляции