🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Integrated Software Inc. Sat, 23 Sep 1995 16:07
members of const objects
#2013
Author: Integrated Software Inc.
Date: Sat, 23 Sep 1995 16:07
57 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads