Reputation: 1526
test.cpp
#include "test.hpp"
void f1() { }
namespace {
void f2() {}
}
namespace test {
void f3() { }
}
Please correct me if I'm wrong, but:
f1
can be called from outside if it is declared in the header file or an extern
statement is usedf2
can't be called from outsidef3
can be called from outside if it is declared in the header file (and properly prefixed - test::
). If it is not declared in a header, it can't be called?Am I right?
Upvotes: 2
Views: 3814
Reputation: 72063
Your question title is misleading. Don't put an anonymous namespace in a header, ever.
f2
can't be called from outside of test.cpp, correct.
f1
and f3
can be called if appropriate declarations are available. These can be in a header, but nothing stops other .cpp files from simply having the code that would be in a header, even if you don't provide one.
Also, extern
is not needed for function declarations.
void f1();
namespace test {
void f3();
}
Upvotes: 3