Connecting Tech Pros Worldwide Forums | Help | Site Map

Sealed Classes in C++

Bharat Karia
Guest
 
Posts: n/a
#1: Jul 23 '05
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.

Thanks
Bharat Karia



Ioannis Vranos
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Sealed Classes in C++


Bharat Karia wrote:
[color=blue]
> 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.[/color]


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%20draft%201.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.




--
Ioannis Vranos

http://www23.brinkster.com/noicys
Ioannis Vranos
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Sealed Classes in C++


Ioannis Vranos wrote:
[color=blue]
> 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.[/color]


That is also mentioned here:

http://blogs.msdn.com/branbray/archi.../07/51007.aspx




--
Ioannis Vranos

http://www23.brinkster.com/noicys
Ioannis Vranos
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Sealed Classes in C++


Ioannis Vranos wrote:
[color=blue]
> 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.[/color]


My mistake here, as it was stated in the draft, it has its uses.




--
Ioannis Vranos

http://www23.brinkster.com/noicys
Sharad Kala
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Sealed Classes in C++



"Bharat Karia" <bjkaria@hotmail.com> wrote in message[color=blue]
> 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[/color]
achieve[color=blue]
> the same effect? i.e. deriving from a sealed class is an error and the
> compiler should flag it as such.[/color]

OP: http://www.research.att.com/~bs/bs_faq2.html#final
Others: Is this covered in the FAQ ?

Sharad


David Hilsee
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Sealed Classes in C++


"Sharad Kala" <no_spam.sharadk_ind@yahoo.com> wrote in message
news:349f36F4853khU1@individual.net...[color=blue]
>
> "Bharat Karia" <bjkaria@hotmail.com> wrote in message[color=green]
> > 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[/color]
> achieve[color=green]
> > the same effect? i.e. deriving from a sealed class is an error and the
> > compiler should flag it as such.[/color]
>
> OP: http://www.research.att.com/~bs/bs_faq2.html#final
> Others: Is this covered in the FAQ ?[/color]

Yes, by question 23.8 ("How can I set up my class so it won't be inherited
from?")

--
David Hilsee


Closed Thread