Connecting Tech Pros Worldwide Help | Site Map

const base subobject

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 09:00 AM
Dave
Guest
 
Posts: n/a
Default const base subobject

Any thoughs on why a member subobject may be const but an inherited
subobject may not? i.e. the following is not possible:

class derived: public const base
{
....
};

but the following is:

class derived
{
....
const base b;
};

The only restriction for the second case is that constructors must
initialize base in its initializer list...

Of course, this also all applies to volatile as well...



  #2  
Old July 22nd, 2005, 09:00 AM
Howard
Guest
 
Posts: n/a
Default Re: const base subobject


"Dave" <better_cs_now@yahoo.com> wrote in message
news:1073j04skqvqm32@news.supernews.com...[color=blue]
> Any thoughs on why a member subobject may be const but an inherited
> subobject may not? i.e. the following is not possible:
>
> class derived: public const base
> {
> ...
> };
>
> but the following is:
>
> class derived
> {
> ...
> const base b;
> };
>
> The only restriction for the second case is that constructors must
> initialize base in its initializer list...
>
> Of course, this also all applies to volatile as well...
>
>[/color]

Well, what would you want the first version for? The base class that is
inherited is not a "sub-object", it's a base class. You're declaring an
object at the time, and saying that class derived is derived from class
base. What would it mean to you to say that the class type it derives from
is const? A type is neither const nor non-const. An instance, however, can
be const, and that is what the member b is, a const instance of an object of
type base.

-Howard


  #3  
Old July 22nd, 2005, 09:00 AM
Howard
Guest
 
Posts: n/a
Default Re: const base subobject


"Dave" <better_cs_now@yahoo.com> wrote in message
news:1073j04skqvqm32@news.supernews.com...[color=blue]
> Any thoughs on why a member subobject may be const but an inherited
> subobject may not? i.e. the following is not possible:
>
> class derived: public const base
> {
> ...
> };
>
> but the following is:
>
> class derived
> {
> ...
> const base b;
> };
>
> The only restriction for the second case is that constructors must
> initialize base in its initializer list...
>
> Of course, this also all applies to volatile as well...
>
>[/color]

Well, what would you want the first version for? The base class that is
inherited is not a "sub-object", it's a base class. You're declaring an
object at the time, and saying that class derived is derived from class
base. What would it mean to you to say that the class type it derives from
is const? A type is neither const nor non-const. An instance, however, can
be const, and that is what the member b is, a const instance of an object of
type base.

-Howard


 

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,662 network members.