some quirks of Koenig lookup rule?
  Home FAQ Contact Sign in
Your Ad Here
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c++.moderated Profile…

 Up
some quirks of Koenig lookup rule?         


Author: Michael Kilburn
Date: May 6, 2008 06:30

Hi

Can someone explain this peculiar behavior of MSVC & GCC:
code below, if you uncomment that line (which is totally unrelated to
'dph' class), will stop compiling with usual bizzare C++ error

[code]
#include

namespace AAA {
struct gad
{
};

//std::ostream& operator<<(std::ostream& s, gad const&);

struct dph
{
void f();
};

}
Show full article (0.77Kb)
4 Comments
Re: some quirks of Koenig lookup rule?         


Author: Bo Persson
Date: May 6, 2008 11:14

Michael Kilburn wrote:
> Hi
>
> Can someone explain this peculiar behavior of MSVC & GCC:
> code below, if you uncomment that line (which is totally unrelated
> to 'dph' class), will stop compiling with usual bizzare C++ error
>
> [code]
> #include
>
> namespace AAA {
> struct gad
> {
> };
>
> //std::ostream& operator<<(std::ostream& s, gad const&);
>
> struct dph
> {
> void f(); ...
Show full article (1.25Kb)
no comments
Re: some quirks of Koenig lookup rule?         


Author: nickf3
Date: May 6, 2008 11:14

On May 6, 10:24 am, Michael Kilburn gmail.com> wrote:
> Hi
>
> Can someone explain this peculiar behavior of MSVC & GCC:
> code below, if you uncomment that line (which is totally unrelated to
> 'dph' class), will stop compiling with usual bizzare C++ error
>
> [code]
> #include
>
> namespace AAA {
> struct gad
> {
> };
>
> //std::ostream& operator<<(std::ostream& s, gad const&);
>
> struct dph
> {
> void f(); ...
Show full article (1.09Kb)
no comments
Re: some quirks of Koenig lookup rule?         


Author: Thomas Maeder
Date: May 6, 2008 11:40

Michael Kilburn gmail.com> writes:
> Can someone explain this peculiar behavior of MSVC & GCC:

Yes.

NB: Your question isn't related to argument dependant (aka Koenig)
lookup. It's a basic overloading problem (if these exist at all).
> code below, if you uncomment that line (which is totally unrelated to
> 'dph' class), will stop compiling with usual bizzare C++ error

It's unrelated to struct dph, but it's related to that type's
operator<<().
Show full article (1.49Kb)
no comments
Re: some quirks of Koenig lookup rule?         


Author: dizzy
Date: May 7, 2008 09:50

Thomas Maeder wrote:
>> void AAA::dph::f()
>> {
>> std::cout << *this;
>
> This statement causes the compiler to look for operator<<()s in a
> sequence of scopes.
>
> The first scope considered is the struct dph, which doesn't have an
> operator<<() member.

Minor correction, woldn't actually look it up in std::cout's as a member and
not in struct dph? (since dph is a second argument to op<< and not the
first).

--
Dizzy

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments