I have a function called test
in namespace buzz
.
From this test function i am calling another function called dummy
which is inside namespace example
.
I get the following error:
Dummy is not a member of example.
Can you please tell me how to communicate between 2 different namespaces?
Thanks
If the namespace is not nested, you should start navigating from the root one, i.e.:
Instead of:
example::dummy
Write:
::example::dummy
Following code works with gcc (as expected). Your problem must be with something that is not in the question.
#include <iostream>
namespace example
{
void dummy() { std::cout << "Dummy\n"; }
}
namespace buzz
{
void test() { example::dummy(); }
}
int main()
{
buzz::test();
}
You need to provide code for this query. Otherwise just from your question, I guess you are making spelling error:
namespace example {
void dummy() {}
}
namespace buzz {
void test () { example::Dummy(); } // capital 'D' instead of 'd' for dummy
}
Naturally, Dummy is not a member of example.
:))
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