Article View: comp.std.c++
Article #2013members of const objects
From: Integrated Software Inc.
Date: Sat, 23 Sep 1995 16:07
Date: Sat, 23 Sep 1995 16:07
57 lines
1822 bytes
1822 bytes
Given:
class A {
public:
char* p;
};
const A& a = someA;
Is the type of a.p: const char* const or char* const?
Section 9 [class] of the April working paper does not seem to say anthing
about members of constant objects, except in passing in 9.4.2.
3.9.3.3 says:
> Each non-function, non-static, non-mutable member of a const-qualified
> class object is const-qualified, each non-function, non-static member of
> a volatile-qualified class object is volatile-qualified and similarly for
> members of a const-volatile class. See 8.3.5 and 9.4.2 regarding
> cv-qualified function types.
It does not say what const-qualified means for a T*, or T&.
Can someone tell me?
My compiler says that a.p is a char* const.
This opens up an ugly hole in const-ness:
class D;
class B {
public:
D* d;
B(D* rd) : d(rd) { }
};
class D: public B {
public:
int i;
D(int x) : B(this), i(x) { }
};
void f(const B& b) { b.d->i = 0; }
int main()
{
D d(10);
cout << d.i << endl;
f(rb);
cout << d.i << endl;
return 0;
}
Here we pass d to f() as a const B&, expecting that the const-ness will
protect d.
Thanks for any clarifications.
Atman Binstock
Integrated Software Inc.
isi@panix.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<43sjk9$5jk@panix.com>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 23 Sep 95 16:07:47 GMT Approved: fjh@cs.mu.oz.au From: isi@panix.com (Integrated Software Inc.) Newsgroups: comp.std.c++ Subject: members of const objects X-Original-Date: 21 Sep 1995 16:57:45 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <43sjk9$5jk@panix.com>