5

I have a function called testin 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

0

3 Answers 3

5

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(); } 
Sign up to request clarification or add additional context in comments.

Comments

4

If the namespace is not nested, you should start navigating from the root one, i.e.:

Instead of:

example::dummy 

Write:

::example::dummy 

1 Comment

don't think so - all my code is within namespace namespace myns {/*my code*/}, and I am perfectly able to call 3rd party functions from their namespaces, starting with std. I think we should look at the code
2

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. :))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.