Connecting Tech Pros Worldwide Help | Site Map

const base subobject

  #1  
Old July 22nd, 2005, 10:00 AM
Dave
Guest
 
Posts: n/a
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, 10:00 AM
Howard
Guest
 
Posts: n/a

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, 10:00 AM
Howard
Guest
 
Posts: n/a

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
A deque containing different types of objects (with a common baseclass) Juha Nieminen answers 15 September 16th, 2007 08:25 PM
Assignment through base class reference anongroupaccount@googlemail.com answers 11 January 22nd, 2006 02:15 AM
const base subobject Dave answers 2 July 22nd, 2005 09:31 AM
Initializing a base class Dave answers 8 July 22nd, 2005 05:35 AM