Connecting Tech Pros Worldwide Help | Site Map

const base subobject

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


Howard
Guest
 
Posts: n/a
#2: Jul 22 '05

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


Howard
Guest
 
Posts: n/a
#3: Jul 22 '05

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