Topic: Why can't a static member function be const?


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Sat, 20 Nov 1993 08:43:58 GMT
Raw View
In article <1993Nov9.205937.23469@gill.uucp> weigang@gill.uucp (Weigang Xu) writes:
>In the page 247 of Stanley B. Lippman's <C++ Primer> (2nd Edition), it
>says:
>"The definition of a static member function is the same as that of a
>nonstatic class member function except that it may not be declared as
>either const or volatile."
>
>Is there any particular reason for why a static member function cannot be
>declared const? Are the reasons for this limitation conceptual or
>just ease of implementation (no this pointer that can be made const)?

Despite the quotation from Lippman, I see no rule in section 9.4 of the
ARM (or section 9.4 of the current draft C++ standard) which prohibits
static member functions from being const, volatile, or const volatile
member functions... and in fact, some compilers allow that.

(Follow-ups to comp.std.c++ please.)

--

-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------




Author: jamshid@ses.com (Jamshid Afshar)
Date: Mon, 22 Nov 1993 05:01:09 GMT
Raw View
In article <rfgCGs89B.8zK@netcom.com>,
Ronald F. Guilmette <rfg@netcom.com> wrote:
>Despite the quotation from Lippman, I see no rule in section 9.4 of the
>ARM (or section 9.4 of the current draft C++ standard) which prohibits
>static member functions from being const, volatile, or const volatile
>member functions... and in fact, some compilers allow that.

Those compilers are buggy.  8.2.5: "A cv-qualifier-list can be part of
a declaration or definition of a nonstatic member function, and of a
pointer to a member function ..."  In anticipation of your next
argument, the WP (and maybe even later ARM printings) insert the word
"only" in "can be".

Jamshd Afshar
jamshid@ses.com