Topic: Question about friend functions


Author: bronsard@iname.com
Date: 2000/02/11
Raw View
Hello all,

I'm trying to figure out if the following code is legal C++ or not.
Currently, VC++ compiles it without problems while GCC (2.75) complains
of a parse error.  Here is the code:

int f1() { return 1; }

class m3 { public :
    int f1() {return 2;};

    friend int ::f1();  // This declaration fails with a parser error
message
};

So is this legal or not?

Thanks in advance,
Francois


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ingo Ciechowski <ciechowski@cis-computer.com>
Date: 2000/02/11
Raw View
On Fri, 11 Feb 2000 9:38:57 +0100, bronsard@iname.com wrote
(in message <87v04e$m4c$1@nnrp1.deja.com>):

> int f1() { return 1; }
>
> class m3 { public :
>     int f1() {return 2;};
>     friend int ::f1();
> };
>
> So is this legal or not?


As far as my knowledge of the standard allows I consider that legal.


--

Ingo
ciechowski@cis-computer.com

________________________________________________________________________
Training fuer IT-Profis ( siehe http://cis-computer.com/training )
Configuration Management  -  Intranet/Internet  -  Perl  -  Java  -  C++

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: brahms@mindspring.com (Stan Brown)
Date: 2000/02/12
Raw View
[This followup was also e-mailed to the cited author for speed --
please follow up in the newsgroup.]

Said bronsard@iname.com (bronsard@iname.com) in comp.std.c++:
>int f1() { return 1; }
>
>class m3 { public :
>    int f1() {return 2;};
>
>    friend int ::f1();  // This declaration fails with a parser error
>message
>};
>
>So is this legal or not?

I'm a bit suspicious of that semicolon ";" after the definition
of m3::f1.

--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
                http://www.mindspring.com/~brahms/
C++ FAQ Lite: http://www.cerfnet.com/~mpcline/c++-faq-lite/
the C++ standard: http://webstore.ansi.org/
more FAQs: http://www.mindspring.com/~brahms/faqget.htm

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]