How can I prevent a class from being inherited
-
How can I prevent a class from being inherited? My idea is to declare the constructor of the base class to be prviate. Is it correct? For example class A { private: A() {}; public: ~A() {}; } class B : public A { public: B() {}; ~B() {}; } int main() { B b; return 0; } As I compile the program, error C2248 happen. Is it all right? Is there any good idea of preventing a class from being inherited? many thanks.
-
How can I prevent a class from being inherited? My idea is to declare the constructor of the base class to be prviate. Is it correct? For example class A { private: A() {}; public: ~A() {}; } class B : public A { public: B() {}; ~B() {}; } int main() { B b; return 0; } As I compile the program, error C2248 happen. Is it all right? Is there any good idea of preventing a class from being inherited? many thanks.
Have a look at sealed keyword.
#region signature my articles #endregion
-
Have a look at sealed keyword.
#region signature my articles #endregion
-
Excuse me, I can't find any subjects I want in your articles. Can you give me a link to it or say in more details? thanks.
I didn't mean my articles, it's just my signature. Just look up sealed keyword.
#region signature my articles #endregion
-
I didn't mean my articles, it's just my signature. Just look up sealed keyword.
#region signature my articles #endregion
-
You are welcome :)
#region signature my articles #endregion