Topic: static const function member
Author: Alexander Novikov <alexrew@dataforce.net>
Date: 1999/05/22 Raw View
is there in c++ standart any prohibition of using
modifier const with static function members,
and (if yes) where is it in standart?
and how it can be explained?
PS: if you can, please reply to e-mail (alexrew@dataforce.net)
because i don't read this newsgroup often...
thanks
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@eng.sun.com (Steve Clamage)
Date: 1999/05/23 Raw View
Alexander Novikov <alexrew@dataforce.net> writes:
>is there in c++ standart any prohibition of using
>modifier const with static function members,
>and (if yes) where is it in standart?
It's not allowed. See section 9.3.1 paragraph 3.
>and how it can be explained?
It makes no sense on a const member function. The const
qualifier on a member function, as in
class T {
...
int f() const;
};
means that the "this" pointer is treated as a pointer to const T,
and that the type of function f is "const member function". It
has no other significance. A static member function has no "this"
pointer, so there is no meaning to attach to the "const".
Sometimes people explain the const as meaning you can't modify
the object. That loose definition is not quite correct, and
leads to other misunderstandings.
>PS: if you can, please reply to e-mail (alexrew@dataforce.net)
>because i don't read this newsgroup often...
Sorry, no. Post in the newsgroup, read answer in the newsgroup.
If you can't be bothered to read the newsgroup, why should
any of us bother to answer your question?
--
Steve Clamage, stephen.clamage@sun.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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/05/23 Raw View
Alexander Novikov wrote:
>
> is there in c++ standart any prohibition of using
> modifier const with static function members,
> and (if yes) where is it in standart?
Section 9.4.1, p2:
"[_Note:_ a static member function does not have a _this_ pointer
(9.3.2). ] A static member function shall not be virtual. Theres shall
not be a static and a nonstatic member function with the same name and
the same parameter types (13.1). A static member function shall not be
declared const, volatile, or const volatile."
> and how it can be explained?
Very simple - 'const' and 'volatile', on member functions, describe the
qualifications covering those functions' access to the particular object
that they are called for. Static member functions aren't associated with
any particular object, but only with the class as a whole. The whole
concept of 'const' or 'volatile' would be meaningless for a static
function.
The same reason is behind the prohibition on 'virtual'. That keyword
indicates that the actual function called depends upon the dynamic type
of the associated object. Since there is no associated object for static
member functions, there would be no way to determine the dynamic type.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]