Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ sealed and interface

Tags:

sealed

c++-cli

I noticed that there are sealed and interface keywords in C++. Is this just for CLR C++? If not, when were sealed and interface added to the C++ standard? Do they have the same meaning in C++ as they do in C#? If not, how do I get the equivalent in standard C++?

like image 680
Tom Avatar asked Dec 04 '22 14:12

Tom


2 Answers

sealed and interface keywords are only for C++/CLI. See Language Features for Targeting the CLR for more details.

In standard C++ interface could be replaced with pure virtual class and multiple inheritance. Sealed keyword could be replaced with boost::noninheritable (which is not an official part of boost yet).

like image 183
Kirill V. Lyadvinsky Avatar answered Feb 08 '23 11:02

Kirill V. Lyadvinsky


An interface can be duplicated in C++ with a pure virtual class, taking advantage of the fact that you can do multiple inheritance.

sealed can be winged with a private constructor and a sort of factory pattern (to actually obtain instances of the sealed class). There's a couple other examples at the C++ FAQ Lite.

like image 20
Mark Rushakoff Avatar answered Feb 08 '23 12:02

Mark Rushakoff