/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void GlobalFunction() {
Engine::LOG(Engine::LOG_PRIORITY::INFO, "Called.");
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
namespace MyNamespace {
void NamespacedFunction() {
Engine::LOG(Engine::LOG_PRIORITY::INFO, "Called.");
GlobalFunction(); // No matching signatures to 'GlobalFunction()'
::GlobalFunction(); // No matching signatures to '::GlobalFunction()'
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void main() {
GlobalFunction();
MyNamespace::NamespacedFunction();
}
I first noted this problem when attempting to use sqrt (from the scriptmath addon) from within a namespaced function. I worked around it by registering scriptmath inside a "Math" namespace, but that's hardly ideal. To me all functions in a parent namespace, unless masked by another function in a closer relation, such as the same namespace, should be accessible in all children namespaces. If a function is masked, it should be accessible with the right use of scope resolution.
Which leads me to: the global scope operator doesn't play with namespaces. This could make situations like the below rather interesting...
void MyFunction() {
Engine::LOG(Engine::LOG_PRIORITY::INFO, "Called.");
}
namespace MyNamespace {
void MyFunction() {
Engine::LOG(Engine::LOG_PRIORITY::INFO, "Called.");
}
void NamespacedFunction() {
MyFunction(); // Which function is this referencing? I assume it's the one in the current namespace!
::MyFunction(); // Which implies that this should be the syntax to access the one in the global namespace...
}
}
I understand the global scope operator is currently designed to access global variables, as in:
// From http://www.angelcode.com/angelscript/sdk/docs/manual/doc_expressions.html
int value;
void function()
{
int value; // local variable overloads the global variable
::value = value; // use scope resolution operator to refer to the global variable
}
However, as it is also the namespace resolution operator I was expecting it to work for accessing the global namespace as well...