But, I declared it inside the zge namespace in my header, so when it couldn't find radiansToDegrees, shouldn't it have looked in the zge namespace which was included when I included the header? |
It did, but you had not defined a function in the namespace zge with that name. There was no such function defined inside the namespace.
You had declared it, but when you defined it, you didn't define it inside any namespace. The function was just a global function at the top level, and you told the compiler that you had put the function inside the zge namespace.
This is exactly what namespaces are for; so you can have functions with the same name, and by putting them in different namespaces you can keep them distinct.
Here is what you did:
Declare them to be inside namespace zge:
1 2 3 4 5
|
namespace zge
{
float radiansToDegrees(float, const float argPi = 3.14159265);
float degreesToRadians(float, const float argPi = 3.14159265);
}
|
Defining them
outside namespace zge...
1 2 3 4 5 6 7 8 9 10 11
|
using namespace zge;
float radiansToDegrees(float argRadians, const float argPi)
{
return argRadians * (180 / argPi);
}
float degreesToRadians(float argDegrees, const float argPi)
{
return argDegrees * (argPi / 180);
}
|
Trying to use the function inside zge, which has never been written. Only the one outside zge has been written, but the compiler won't use that one because you have very clearly said that this function is the one from inside namespace zge.
double radians = zge::degreesToRadians(Rect.getRotation());
So you created the function
outside the namespace zge, but then told the compiler to use the one from
inside the namespace - which has never been written.