This is really trivial but I'm getting an error I didn't expect.
I have some code which is inside of a namespace
the following is some pseudocode that represents the structure of my code:
namespace A {
void init() {
initialize_kitchen_sink();
}
#include "operations.h" // declares shake_and_bake()
void foo() {
shake_and_bake();
}
void cleanup() {
// do nothin' cuz i'm a slob
}
}
error:
undefined reference to `A::shake_and_bake`
Turns out moving the #include
outside the namespace will fix it.
As it was, the include would be in effect declaring all of the functions in operations.h
inside the A
namespace. Then it would search in vain for the implementations.
I figure instead of deleting my entire post i may as well leave it for that minute possibility that someone else may stumble upon a similar problem and be enlightened.
To answer precisely to your question, you can reference something from the global namespace by using :: as your first statement as in :
void foo() {
::shake_and_bake();
}
Of course, your answer, for this special case is right though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With