This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Namespace Lookup


> Because of a rule called Koenig lookup [basic.lookup.koenig].  For
> short, it states that a function argument of a particular class type
> causes functions in the scope of that class to be considered for
> overload resolution.

Thanks for the pointer. Let me see whether I understand this correcly.
There is a set of associated namespaces and classes for the call, and
lookup searches all of them (unless it first finds a member). So

namespace A{
  namespace B{
    struct X;
  }
  void f(struct B::X);
  namespace B{
    struct X{
      friend void A::f(X);
    };
    void f(int, X &);
  }
}
void g()
{
  A::B::X x;
  f(4,x);   //calls A::B::f(int, A::B::X&);
  f(x);     //calls A::f(A::B::X);
}

is correct. What about

struct Foo{
  int bar;
};
void bar(Foo&);
void foobar()
{
  Foo quux;
  bar(quux);  //error: call to non-function Foo::bar
}

It seems that Koenig lookup considers Foo, and finds its member bar.
It then sees that it is not a function, so the call is invalid. Right?

Now, what about

struct Foo{
  static int bar(Foo&);
};

bar(int);

void foobar(Foo quux)
{
  bar(quux);
}

This should find both ::bar, and Foo::bar, and select the latter. Right?

TIA,
Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]