From: Michael Kilburn on
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 <iostream>

namespace AAA {
struct gad
{
};

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

struct dph
{
void f();
};

}

std::ostream& operator<<(std::ostream& s, AAA::dph const&)
{
return s;
}

void AAA::dph::f()
{
std::cout << *this;
}

int main(int argc, char* argv[])
{
return 1;
}
[/code]

Sincerely yours,
Michael.

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

From: dizzy on
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! ]