const base subobject

D

Dave

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...
 
H

Howard

Dave said:
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...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top