Re: static member function and const
On Nov 13, 8:43 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.com> wrote:
why can't a static member function be declared as const ?
We can declare a non-static member function as const,
to indicate that it does not modify the non-mutable data
members of a class.
Slightly imprecise: The const-qualification specifies whether
the member function does potentially modify a given instance
of a class, more specifically a const member function can be
thought of having a hidden this-pointer to the *const* class
type and acting with this pointer. From this we can easily
recognize that mutable operations conflict with this const-
qualification. Static member functions don't have any this
pointer.
In the same way, is there a provision
to indicate that a static member function does not modify
the static data members but only uses their values ?
In C++ there does not exist the concept of a class instance,
which would be necessary to make that approach reasonable.
*If* C++ would express classes itself as first-class objects
(some other languages do this with a so-called meta class
concept), than we would probably distinguish "pure" static
member functions (which are similar to free functions and
reflect the current concept of static function members) from
"class-static" functions, which would have a hidden pointer
to the meta class object (and not an individual this pointer).
For similar reasons C++ does not support virtual static
functions (which would make sense, if you consider
polymorphic meta-classes).
If you need such behaviour, you have to create your own
meta-class approach, which is solvable via pure language
means.
HTH & Greetings from Bremen,
Daniel KrLgler
---
[ 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.comeaucomputing.com/csc/faq.html ]