Tag Archives: koenig lookup

C++ koenig lookup problem

Why does not the following code compile?

 #include <iostream>
// Does Koenig lookup work only for derived datatypes?
namespace FBB
{
  float y;
  class T
  {
    ;
  };
  T a;
  void classTest(T arg)
  {
    std::cout<<"Inside class test"<<std::endl;
    return;
  }

  void fun(float x)
  {
    std::cout << "fun called for " << x << std::endl;
  }
}

int main()
{
  classTest(FBB::a);
  // this line does not compile
  //  fun(FBB::y);
  FBB::fun(FBB::y); // works
  // for fun()
}


Advertisements