This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 3.0 template problem - only for C++ professionals or a bug ?
- To: Helmut Schröger <helmut dot schroeger at rl-ag dot de>
- Subject: Re: gcc 3.0 template problem - only for C++ professionals or a bug ?
- From: Phil Edwards <pedwards at disaster dot jaj dot com>
- Date: Mon, 23 Jul 2001 05:19:08 -0400
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <PPEGJBKFIFHFBJFLPDIMKEALCGAA.helmut.schroeger@rl-ag.de>
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