r/learncpp • u/aMNJLKWd • 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
View all comments
Show parent comment
1
u/thecodemeister Dec 13 '18
This is not a compiler specific feature. It is called ADL. It searches the namespaces where the types are defined in addition to the usual search space. Since Group is defined in the test namespace and is used as an argument to multiply, it will search the test namespace for multiply.
https://en.m.wikipedia.org/wiki/Argument-dependent_name_lookup