Topic: const classes
Author: kanze@gabi-soft.de
Date: Sun, 15 Oct 2000 03:12:37 GMT Raw View
MikeAlpha@NoSpam_csi.com (Martin Aupperle) writes:
|> On Tue, 10 Oct 2000 18:09:09 GMT, Francis Glassborow
|> <francis.glassborow@ntlworld.com> wrote:
|> >In article <39e1724d.695724@news.nikoma.de>, Martin Aupperle
|> ><MikeAlpha@NoSpam_csi.com> writes
|> >>Learned something new here - thanks. But this is possible (works wi=
th
|> >>VC):
|> >> struct S1 { ... };
|> >> typedef const S1 S2;=20
|> >>so it seems that we have a situation where we need typedef to make =
a
|> >>type.=20
|> >No, you haven't created a type, just provided a simple name for an
|> >existing type that otherwise requires a multi token name.
|> Can you then please give that "multi token name"?
S1 const
Perhaps what you meant to say is that we have a type which cannot be
declared directly -- I can only do it with a typedef, or on a
declaration by declaration basis. But this is characteristic of
cv-qualifiers.
--=20
James Kanze mailto:kanze@gabi-soft.de
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/12 Raw View
On Tue, 10 Oct 2000 18:09:09 GMT, Francis Glassborow
<francis.glassborow@ntlworld.com> wrote:
>In article <39e1724d.695724@news.nikoma.de>, Martin Aupperle
><MikeAlpha@NoSpam_csi.com> writes
>>Learned something new here - thanks. But this is possible (works with
>>VC):
>>
>> struct S1 { ... };
>> typedef const S1 S2;
>>
>>so it seems that we have a situation where we need typedef to make a
>>type.
>
>No, you haven't created a type, just provided a simple name for an
>existing type that otherwise requires a multi token name.
>
Yes, - I know that typename normaly is just another name for an
existing type. But here we seem to have a situation where we need
typedef. Or can you give a definition for S2 without typedef? That is,
can you write down that "multi token name"?
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/12 Raw View
On Tue, 10 Oct 2000 18:09:09 GMT, Francis Glassborow
<francis.glassborow@ntlworld.com> wrote:
>In article <39e1724d.695724@news.nikoma.de>, Martin Aupperle
><MikeAlpha@NoSpam_csi.com> writes
>>Learned something new here - thanks. But this is possible (works with
>>VC):
>>
>> struct S1 { ... };
>> typedef const S1 S2;
>>
>>so it seems that we have a situation where we need typedef to make a
>>type.
>
>No, you haven't created a type, just provided a simple name for an
>existing type that otherwise requires a multi token name.
>
Can you then please give that "multi token name"?
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/12 Raw View
>Another option:
>
>typedef struct S1 { int i } const S2;
>
When I remember right, the definitions of
struct A { ... };
and
typedef struct { ... } B;
are different. I once had a situation where A works, but not B (gave
zilions of compiler errors). It was a large projekct, incorporated
extern "C-linkage structures etc, and it was some time ago (old
CFront-compiler). Have things changed today?
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 2000/10/10 Raw View
James Kuyper wrote:
>
> Martin Aupperle wrote:
> >
> > Hello,
> > I defined something like
> >
> > struct S1 { int i; };
> > const struct S2 { int i; };
> >
> > I expected that objects of S2 are always const objects, e.g. that
> > statements like
> >
> > S2 s;
> > s.i = 1; // ???
> >
> > are errors.
> > But with my compiler, S1 and S2 behave identically. Is this by design
> > or is my compiler broken here? (I use VC6).
>
> You're misinterpreting a language feature. It's legal to place 'const'
> in that location, but it's pointless to do so unless the structure
> declaration defines an object, as well as declaring it:
>
> const struct S2 { int i; } const_object;
>
> The closest you can get to what you want is:
>
> struct S2 { const int i; };
Another option:
typedef struct S1 { int i } const S2;
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/10/10 Raw View
In article <39e1724d.695724@news.nikoma.de>, Martin Aupperle
<MikeAlpha@NoSpam_csi.com> writes
>Learned something new here - thanks. But this is possible (works with
>VC):
>
> struct S1 { ... };
> typedef const S1 S2;
>
>so it seems that we have a situation where we need typedef to make a
>type.
No, you haven't created a type, just provided a simple name for an
existing type that otherwise requires a multi token name.
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/08 Raw View
Hello,
I defined something like
struct S1 { int i; };
const struct S2 { int i; };
I expected that objects of S2 are always const objects, e.g. that
statements like
S2 s;
s.i = 1; // ???
are errors.
But with my compiler, S1 and S2 behave identically. Is this by design
or is my compiler broken here? (I use VC6).
Further, I observed that
typedef const S1 S3;
works as expected: Objects of S3 are always const.
Martin
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: James Kuyper <kuyper@wizard.net>
Date: Mon, 9 Oct 2000 00:10:06 GMT Raw View
Martin Aupperle wrote:
>
> Hello,
> I defined something like
>
> struct S1 { int i; };
> const struct S2 { int i; };
>
> I expected that objects of S2 are always const objects, e.g. that
> statements like
>
> S2 s;
> s.i = 1; // ???
>
> are errors.
> But with my compiler, S1 and S2 behave identically. Is this by design
> or is my compiler broken here? (I use VC6).
You're misinterpreting a language feature. It's legal to place 'const'
in that location, but it's pointless to do so unless the structure
declaration defines an object, as well as declaring it:
const struct S2 { int i; } const_object;
The closest you can get to what you want is:
struct S2 { const int i; };
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/09 Raw View
On Mon, 9 Oct 2000 00:10:06 GMT, James Kuyper <kuyper@wizard.net>
wrote:
>
>You're misinterpreting a language feature. It's legal to place 'const'
>in that location, but it's pointless to do so unless the structure
>declaration defines an object, as well as declaring it:
>
> const struct S2 { int i; } const_object;
>
Learned something new here - thanks. But this is possible (works with
VC):
struct S1 { ... };
typedef const S1 S2;
so it seems that we have a situation where we need typedef to make a
type.
>The closest you can get to what you want is:
>
> struct S2 { const int i; };
>
Or, the typedef solution above.
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: wmm@fastdial.net
Date: 2000/10/09 Raw View
In article <39e04a6a.2034211@news.nikoma.de>,
MikeAlpha@NoSpam_csi.com (Martin Aupperle) wrote:
> I defined something like
>
> struct S1 { int i; };
> const struct S2 { int i; };
>
> I expected that objects of S2 are always const objects, e.g. that
> statements like
>
> S2 s;
> s.i = 1; // ???
>
> are errors.
> But with my compiler, S1 and S2 behave identically. Is this by design
> or is my compiler broken here? (I use VC6).
VC6 is broken in this regard -- but not in the way that you
think. It should have reported an error in the declaration of
S2. 7.1.5.1p1 says:
If a cv-qualifier appears in a decl-specifier-seq, the
init-declarator-list of the declaration shall not be
empty.
A class declaration that is not part of a typedef and that does
not declare an object has an empty declarator list (the object
name or typedef name is a declarator). The upshot is that you
can't declare a given class or enum type to be const, only a
particular object or typedef name.
--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: comeau@panix.com (Greg Comeau)
Date: 2000/10/09 Raw View
In article <39e04a6a.2034211@news.nikoma.de>,
Martin Aupperle <MikeAlpha@NoSpam_csi.com> wrote:
>I defined something like
>
> struct S1 { int i; };
> const struct S2 { int i; };
Your definition of S2 is an error, so....
>I expected that objects of S2 are always const objects, e.g. that
>statements like
>
> S2 s;
> s.i = 1; // ???
>
>are errors.
...we cannot even talk about this.
>But with my compiler, S1 and S2 behave identically. Is this by design
>or is my compiler broken here? (I use VC6).
Sounds like the latter (got the bugger in strict mode?).
>Further, I observed that
>
> typedef const S1 S3;
>
>works as expected: Objects of S3 are always const.
Yes, but that's a different statement than the above.
- Greg
--
Comeau Computing / Comeau C/C++ "so close" 4.2.44 betas NOW AVAILABLE
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]