gcc 3.0 template problem - only for C++ professionals or a bug ?
Phil Edwards
pedwards@disaster.jaj.com
Mon Jul 23 02:17:00 GMT 2001
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
More information about the Gcc-bugs
mailing list