If I have a class definition
class myClass
{
void x();
};
void myClass::x()
{
hello(); // error: ‘hello’ was not declared in this scope
}
void hello()
{
cout << "Hello\n" << endl;
}
How can I call a function defined outside the scope of a class and located in the same file ? I know that I can use Namespace::function but I am not sure in this case what I should use for Namespace
You must at least declare it (if not define it) before its use.
Usually, this is done in an anonymous namespace if the function’s functionality is only used in that translation unit:
This gives the function internal linkage (similar to declaring it
static) and is only available in that TU.