const base subobject

Discussion in 'C++' started by Dave, Apr 5, 2004.

  1. Dave

    Dave Guest

    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...
    Dave, Apr 5, 2004
    #1
    1. Advertising

  2. Dave

    Howard Guest

    "Dave" <> wrote in message
    news:...
    > 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
    Howard, Apr 5, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    393
    myork
    May 23, 2007
  2. Replies:
    1
    Views:
    385
    Victor Bazarov
    May 23, 2007
  3. Javier
    Replies:
    2
    Views:
    558
    James Kanze
    Sep 4, 2007
  4. Fraser Ross
    Replies:
    0
    Views:
    244
    Fraser Ross
    Apr 8, 2009
  5. shinedance
    Replies:
    0
    Views:
    349
    shinedance
    Oct 10, 2011
Loading...

Share This Page