Bharat said:
Hi,
Is it possible to writed Sealed classes in C++ [i.e. similar to sealed
classes in C# or final classes in Java].
i.e. there is no sealed/final keyword in C++, but is it possible to achieve
the same effect? i.e. deriving from a sealed class is an error and the
compiler should flag it as such.
You are talking about .NET (CLI) sealed classes, so you had better check
C++/CLI (currently draft) for that:
http://www.plumhall.com/C++-CLI draft 1.8.pdf
"18.1.1 Class modifiers
To accommodate the addition of sealed and abstract classes, the grammar
for class-head in the C++ Standard (§9) has been extended to include an
optional sequence of class modifiers, as follows:
class-modifiers:
class-modifiers_opt class-modifier
class-modifier:
abstract
sealed
If the same modifier appears multiple times in a class definition, the
program is ill-formed.
[Note: abstract and sealed can be used together; that is, they are not
mutually exclusive. As non-member functions are not CLS-compliant, a
substitute is to use an abstract sealed class, which can contain static
member functions. This is the utility class pattern. end note]
The abstract and sealed modifiers are discussed in §18.1.1.1 and
§18.1.1.2, respectively."
Notice here that you can define a class that is both abstract and sealed
just because the CLI (.NET) permits it, although it is of no use.
That is not possible in C#/CLI, but is possible in C++/CLI because it is
the systems programming language of .NET.
In ISO C++, there is no way to do such a thing portably.