473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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...
Jul 22 '05 #1
2 1585

"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.supernews.com...
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
Jul 22 '05 #2

"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.supernews.com...
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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michael Winter | last post by:
Until about 5 minutes ago, I was happy with my knowledge of virtual functions - then I read "Mixing interface and functional inheritance" posted by Kevin L. earlier today. All of a sudden, I found...
2
by: Dave | last post by:
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:
10
by: ATASLO | last post by:
In the following example, section #3 fails under VC98, VC2003, VC2005 Express Beta (Aug 2004) and g++ 3.3.2. Is this just a pitfall of the C++ specification? Why don't any of the above compilers...
11
by: Thomas Zangl | last post by:
Hi! I have a class hierachie like this: // interface, abstract only class ISession { } // implements common parts of ISession
11
by: anongroupaccount | last post by:
What measures should be taken to avoid this sort of thing? class Base { }; class Derived1 : public Base { private: int i, j, k;
12
by: siddhu | last post by:
Dear experts, #include <stdio.h> class Base { }; class Der1:public Base {
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
7
by: Yen Kwoon | last post by:
Note: This problem is related to gcc but after some back and forth in group gnu.gcc.help it seems to have morph into more of a c++ specificiation question, hence the transplanting to this group. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.