Topic: Is const void foo:bar() valid ?


Author: Timo_Geusch@award.de (Timo Geusch)
Date: 1996/11/22
Raw View
I ran into someone else's code today in which some class member
functions were declared like this:

const void foo::bar() { ... }

Appearently our compiler (MS VC++ 4.2) accepts this as a valid
declaration. I checked my ANSI DWP and found no reference to a similar
construct so I am wondering if it is valid syntax. If so, can somebody
enlighten my on the meaning of this declaration ?
Timo Geusch
PCMCIA software engineer
AWARD Software International, Inc.

"Opinions stated in this message are solely my own and do not reflect the official view of AWARD Software International, Inc in any way"


[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: christian.bau@isltd.insignia.com (Christian Bau)
Date: 1996/11/22
Raw View
In article <32957fcc.4704194@195.30.16.205>, Timo_Geusch@award.de (Timo
Geusch) wrote:

> I ran into someone else's code today in which some class member
> functions were declared like this:
>
> const void foo::bar() { ... }
>
> Appearently our compiler (MS VC++ 4.2) accepts this as a valid
> declaration. I checked my ANSI DWP and found no reference to a similar
> construct so I am wondering if it is valid syntax. If so, can somebody
> enlighten my on the meaning of this declaration ?

const char* foo::bar () { ... } would be a function returning a "const
char*" that is a pointer to const char. Looks reasonable and quite useful.


const int& foo::bar () { ... } returns a reference to a const int. Looks
reasonable and occasionaly useful. An assignment "foo::bar () = 0;" would
be illegal because of the "const".

const int foo::bar () { ... } returns a const int. In this situation there
is no much difference between a "const int" and an "int", because the
function result is an rvalue so you cannot change it anyway. So this means
"even if you could assign to the function result, which you cant, you
wouldnt be allowed to".

const void foo::bar () { ... } returns a const void. Which means the
function returns nothing, and you cannot assign to that nothing that it
returns because it is const. The const does not make any real difference.
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1996/11/23
Raw View
Timo Geusch writes:

> I ran into someone else's code today in which some class member
> functions were declared like this:

> const void foo::bar() { ... }

> Appearently our compiler (MS VC++ 4.2) accepts this as a valid
> declaration. I checked my ANSI DWP and found no reference to a similar
> construct so I am wondering if it is valid syntax. If so, can somebody
> enlighten my on the meaning of this declaration ?

There seems to be no problem with this declaration.  Just the fact
that void is cv-qualified does not make the declaration invalid.
[basic.type.qualifier] makes no exception to the void type regarding
cv-qualifiers.

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br
Universidade Estadual de Campinas, SP, Brasil
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: claus@faerber.muc.de (=?ISO-8859-1?Q?Claus_Andr=E9_F=E4rber?=)
Date: 1996/11/24
Raw View
Hallo Timo, hallo everybody,

Timo Geusch <Timo_Geusch@award.de> wrote on 22 Nov 96:
> I ran into someone else's code today in which some class member
> functions were declared like this:
>
> const void foo::bar() { ... }
>
> Appearently our compiler (MS VC++ 4.2) accepts this as a valid
> declaration. I checked my ANSI DWP and found no reference to a
> similar construct so I am wondering if it is valid syntax. If so,
> can somebody enlighten my on the meaning of this declaration ?

It declares a member function of foo returning a "const void".
What (s)he probably /wanted/ to write was:
  void foo:bar() const { ... }
which declares a function for const foo's.

--=20
Claus Andr=E9 F=E4rber <claus@faerber.muc.de>, <http://www.muc.de/~cfaerb=
er/>
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]