Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Argument-Dependent (Koenig) Lookup Now Supported

Koenig lookup is now fully implemented in the Visual C++ compiler.

For more information, see Argument-Dependent Name (Koenig) Lookup on Functions.

The following sample behaves differently at run time in Visual Studio .NET than it does in Visual Studio .NET 2003

// bc_argument_dependent_AKA_Koenig_lookup_now_supported.cpp
// compile with: /W1
#include <stdio.h>

namespace N {
   class X {};

   void f(X *pX) {
      printf_s("in N::X::f\n");
   };   // called if compiled with 7.1
}

void f(void *pv) {
   printf_s("in ::f\n");
};   // called if compiled with 7.0

int main() {
   N::X *pX = 0;
   f(pX);

   // The following lines will result in the same behavior
   // in Visual Studio .NET or Visual Studio .NET 2003
   f((void*)pX);   // Cast pX to void before calling f; calls global f
   ::f(pX);    // Explicitly specify global f
   N::f(pX);   // Explicitly specify f in namespace
}

Output

in N::X::f
in ::f
in ::f
in N::X::f

Community Additions

ADD
Show:
© 2015 Microsoft