By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,494 Members | 872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,494 IT Pros & Developers. It's quick & easy.

Sealed Classes in C++

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Bharat Karia wrote:
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%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
Jul 22 '05 #2

P: n/a
Ioannis Vranos wrote:
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.

That is also mentioned here:

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


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #3

P: n/a
Ioannis Vranos wrote:
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.

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


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #4

P: n/a

"Bharat Karia" <bj*****@hotmail.com> wrote in message
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.


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

Sharad
Jul 22 '05 #5

P: n/a
"Sharad Kala" <no*****************@yahoo.com> wrote in message
news:34*************@individual.net...

"Bharat Karia" <bj*****@hotmail.com> wrote in message
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.


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


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

--
David Hilsee
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.