Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: const member functions: why bother the programmer? Message-ID: <333@taumet.com> Date: 24 Jul 90 16:29:59 GMT References: <2026@kulcs.kulcs.uucp> Organization: Taumetric Corporation, San Diego Lines: 24 herman@kulcs.uucp (Herman Moons) writes: >Why does the C++ language demand that the programmer states which >member functions are const ?? This seems a job for the compiler, not >for the programmer (after all, the compiler checks whether a function is >really const if we specify it that way). You might want two versions of a member function, depending on whether it deals with a constant object. You have to declare one of them const, since you cannot declare the "this" pointer at all. When you invoke one of these functions, the compiler picks the right one (overload resolution) based on whether the object is const. When there is only one member function with a given signature, the compiler could in principle determine whether any assignments were possibly made to the object, and classify the object as const. This would make part of the function type invisible, requiring every user of this function to read and correctly understand the details of the function code before knowing how to call it. Having a program fail to link as the only diagnostic of this problem seems like a poor idea. -- Steve Clamage, TauMetric Corp, steve@taumet.com