This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc 3.0 template problem - only for C++ professionals or a bug ?


On Mon, Jul 23, 2001 at 10:23:41AM +0200, Helmut Schröger wrote:
> class namespace_t
> {
> public:
>         std::string name;
>         bool operator<(const namespace_t&);
                         ^^^^^

This 'const' tells the compiler that the namespace_t on the right-hand
side of the comparison is constant during the course of the comparison,
but you should also tell the compiler that the namespace_t on the left-hand
side will not be changed during the comparison.  The left-hand object is
'this' during the call to op<, and that is what is generating the warnings.

If you change both declaration and definition of op< to read

    bool operator<(const namespace_t&) const;

you will make op< a "const member function," which tells the compiler that
this function can safely be called by 'const' instances of namespace_t.


Phil

-- 
Would I had phrases that are not known, utterances that are strange, in
new language that has not been used, free from repetition, not an utterance
which has grown stale, which men of old have spoken.
                                     - anonymous Egyptian scribe, c.1700 BC


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]