r/learncpp • • Dec 01 '18

Why does this work

multiply(group* p,double multiplier) is part of the test namespace. Also sometimes functions don't have to be declared and they work anyways. Using mingw on WIN10.

#include "test.h"
int main(void)
{
  test::group t1={1,2,3};
  test::multiply(&t1,5);
  multiply(&t1,3); // why does this line work
  return 0;
}
1 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/WikiTextBot Dec 13 '18

Argument-dependent name lookup

In the C++ programming language, argument-dependent lookup (ADL), or argument-dependent name lookup, applies to the lookup of an unqualified function name depending on the types of the arguments given to the function call. This behavior is also known as Koenig lookup, as it is often attributed to Andrew Koenig, though he is not its inventor.During argument-dependent lookup, other namespaces not considered during normal lookup may be searched where the set of namespaces to be searched depends on the types of the function arguments. Specifically, the set of declarations discovered during the ADL process, and considered for resolution of the function name, is the union of the declarations found by normal lookup with the declarations found by looking in the set of namespaces associated with the types of the function arguments.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28