| Re: some quirks of Koenig lookup rule? |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c++.moderated · Group Profile
Author: nickf3nickf3 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();
> };
>
> }
>
> 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.
>
Michael,
Since names in different scopes do not participate in overloading the
function AAA::operator<< hides the ::operator<< for types in namespace
AAA.
|