How to correctly reference a function in an anonymous namespace

Consider this fragment of C++ code:

namespace
{
    void f()
    {
    }

    class A
    {
        void f()
        {
            ::f(); // VC++: error C2039: 'f' : is not a member of '`global namespace''
        }
    };
}

GCC compiles this just fine. Visual C++ 2008 fails to compile spitting out the C2039 error. Which one of these two compilers is correct here? Is there any way to reference that "global" f properly?

Edit: Zack suggested to try and it works with both compilers. Looks a bit weird to me.

namespace
{
    void f()
    {
    }

    class A
    {
        void f();
    };
}

void A::f()
{
    ::f();
}
20
задан Dan Moulding 31 March 2011 в 17:52
поделиться