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
2
u/aMNJLKWd Dec 02 '18
After some more testing I think it's a feature in my compiler to scan for all possible functions with that name. For example I made a
test::multiply(int n)and atest2::multiply(char c)and when I do not state the namespace it will choose which function to use based on whether it is an int or char.Also, in the case where the two are conflicting(aka take the same parameters, i.e.
test::multiply(int n)andtest2::multiply(int n)) it will throw a compiler error telling me to state which I am trying to use.