On Tue, 19 Feb 2013 03:44:55 -0800, stilewski wrote:
> Another alternative would be to use anonymous namespace, but under
> certain circumstances.
>
> Example:
>
> // A.hpp
> namespace {
> void anonymousFunction() {
> // do sth here...
> }
> }
>
> class A {
> public:
> void fun() { anonymousFunction(); }
> };
>
>
> In above example function `anonymousFunction` is visible only in file
> A.hpp.
And in any file that #include-s A.hpp.
Furthermore, this runs afoul of the one-definition-rule if A.hpp gets
included in two or more translation units, because in each of them A::fun
calls a *different* function (that all, confusingly enough, are called
anonymousFunction).
The correct way is, as Jorgen Grahn showed else-thread, to have the
implementation of both functions in a separate source file.
Bart v Ingen Schenau
|