Is there a way in C++ to create an anonymous namespace, and only export a single function out of it?
I want something like:
namespace {
void Bar() {}
void Foo() { Bar(); }
}
Now, I want to somehow access to Foo() yet make sure there’s no way to touch Bar()
Thanks!
Since you want
Foo()to have external linkage, you should declare it in a header file:Now everyone can see and call
Foo()But in Foo.cpp:
Now, as long as you control the source file Foo.cpp, no one can change access to
Bar()