So, I just started with C++ and was doing random things with a snippet of code I found on the net. The code is a simple use of defining namespace. After my changes in the code, it looked like,
#include <iostream>
using namespace std;
namespace ns1 { int value() {return 5;}}
namespace ns2 { int value() {return -5;}}
int main() {
cout << ns1::value<< '\n'; //5 will be displayed
cout << ns2::value<< '\n'; // -5 will be displayed
}
Now, i know that i have called the wrong function and it should be ns1::value()
instead of ns1::value
, but my question is why is the code still working? And why is it giving an output of 1
?