Topic: CONST DATA MEMBER
Author: martin.horton@chrysalis.org
Date: Tue, 22 Feb 94 09:27:12 Raw View
In article <rfgCLJF7v.1Io@netcom.com> rfg@netcom.com (Ronald F.
Guilmette) wrote:
N>>Yesterday, in a design meeting that got a little too deep into
N>>implementation, someone asked if a const data member was treated like
N>a >static data member by the compiler.
N>>
N>>It would seem that the compiler could know that since the data member
N>could >not be changed it is not necessary to allocate space for it in
N>every >instantiation.
Just because a member is defined as const does NOT mean that its value
will be the same for every instantiation.
class A {
const int i;
int j;
public: A( int ii, int jj ) : i(ii), j(jj) {};
};
A a1(1,2);
A a2(3,4);
a1 and a2 have different values of i, but neither of them may be
changed.
If I am wrong, will someone please correct me, gently!
Martin Horton - Fort Worth, Texas 02/22/94 08:11
Internet:
Personal: Martin.Horton@Chrysalis.org
Business: Z5319@aa1profs.ibmmail.com
Fidonet Martin Horton @ 1:124/4214
Author: warwick@cs.uq.oz.au (Warwick Allison)
Date: 24 Feb 1994 07:06:20 GMT Raw View
martin.horton@chrysalis.org writes:
>Just because a member is defined as const does NOT mean that its value
>will be the same for every instantiation.
100%, and so it should be. BUT, what SHOULD be usable is:
class foo {
public:
static const int i=1234;
};
But alas, this is not allowed. Instead we resort to:
class foo {
public:
enum { i=1234, j=4128 };
};
But this doesn't even extend as far as:
class foo {
public:
enum { x=1.234, y=4.128 };
};
--
Warwick