1

In a file there is an anonymous namespace and a named namespace. Anonymous namespace has some internal function which should not be exposed and the named namespace has some overloaded functions which need to be accessed.

//test.cpp

namespace
{
void func() {}
void crazy()
{
   func(a);
}
}

namespace useful
{
void func(int a)
{
    //something
}
}

Can someone suggest me how to access a named namespace which is written below it ? Is it okay to access a function of a named namespace from an anonymous namespace ?

3
  • 1
    Did you declare the useful::func(int)? Commented Sep 17, 2017 at 1:13
  • 1
    The function ::crazy() needs to be defined AFTER a declaration of useful::func(), not before. Commented Sep 17, 2017 at 1:15
  • thanks, I thought there is some better way to do. Commented Sep 17, 2017 at 18:34

1 Answer 1

1

You can declare in the relevant namespace before it is used and defined:

//test.cpp

namespace useful {
void func(int);
}

namespace
{
void func() {}
void crazy()
{
    useful::func(3);
}
}

namespace useful
{
void func(int a)
{
    //something
}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.