Connecting Tech Pros Worldwide Help | Site Map

Sealed Classes in C++

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 11:30 PM
Bharat Karia
Guest
 
Posts: n/a
Default Sealed Classes in C++

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



  #2  
Old July 22nd, 2005, 11:30 PM
Ioannis Vranos
Guest
 
Posts: n/a
Default 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
  #3  
Old July 22nd, 2005, 11:30 PM
Ioannis Vranos
Guest
 
Posts: n/a
Default 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
  #4  
Old July 22nd, 2005, 11:30 PM
Ioannis Vranos
Guest
 
Posts: n/a
Default 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
  #5  
Old July 22nd, 2005, 11:30 PM
Sharad Kala
Guest
 
Posts: n/a
Default 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


  #6  
Old July 22nd, 2005, 11:31 PM
David Hilsee
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.