From 2422306598240368790
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9ba786ca7952a128
X-Google-Attributes: gidf78e5,public
X-Google-Thread: 109fba,9ba786ca7952a128
X-Google-Attributes: gid109fba,public
From: Marcelo Cantos <marcelo@mds.rmit.edu.au>
Subject: Re: STL overloads != operator of MyClass!
Date: 1997/04/06
Message-ID: <bg7mifttrp.fsf@janus.i-have-a-misconfigured-system-so-shoot-me>#1/1
X-Deja-AN: 231221444
References: <3347DC7E.5861ED04@arrakis.es>
X-Original-Date: 07 Apr 1997 13:07:54 +1000
Organization: Royal Melbourne Institute of Technology, Melbourne, Australia.
X-Auth: PGPMoose V1.1 PGP comp.std.c++
Newsgroups: comp.lang.c++,comp.std.c++
Originator: austern@isolde.mti.sgi.com


Ildefonso Junquero <junquero@arrakis.es> writes:

> I'm using stl that comes whit gcc 2.7.2, and i get surprised because g++
> takes precedence of stl templated operator != than a class operator !=.
> Here is an example :
> 
> 	#include <vector>
> 	#include <algo>
> 	typedef enum MyBool { myFalse, myTrue };
> 
> 	friend ostream& operator<<(ostream&os, const MyBool &mb)
        ^^^^^^ this is illegal.

A function can't declare itself to be the friend of a class.
This the class's prerogative.

> [snip, snip]
> 	The output is :
> 
> 		True
> 		0    <<--- I expected False!
> 
> 	Can someone explain me why?, Is this an g++ bug?
> 	It works like i expected in Borland C++ 4.52 .

FWIW: The Sun compiler (4.2) produces the correct output.

> 	What does the standrad says?

Class members should override global functions.

  13.3.3  Best Viable Function                         [over.match.best]

1 [Paraphrased, F1 beats F2 if...]
  ...
  --F1 is a non-template function and F2 is a template function special-
    ization,...



-- 
______________________________________________________________________
Marcelo Cantos, Research Assistant      __/_   marcelo@mds.rmit.edu.au
Multimedia Database Systems Group, RMIT  /       _  Tel 61-3-9282-2497
723 Swanston St, Carlton VIC 3053    Aus/ralia ><_> Fax 61-3-9282-2490
Acknowledgements: errors - me; wisdom - God; funding - RMIT
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



