This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

__attribute__(visibility("default"))) and nested structures


Hello,

When I write classes in C++ and use the Pimpl idiom, I generally set
the structure up like so:


    Foo.hpp
    -------

    class Foo
    {
    public:
        Foo();
        ~Foo();


        void method1();
        void method2();

    private:
        struct impl;
        std::unique_ptr<impl> p;
    };

    Foo.cpp
    -------

    struct Foo::impl
    {
        method1()
        {
            ....
        }
        method2()
        {
            ...
        }

        private_thing()
        {
            ...
        }

    }

    Foo::Foo():p(make_unique<impl>()){}
    Foo::~Foo(){}
    void Foo::method1(){ p->method1();}
    void Foo::method2(){ p->method2();}

I'd like to hide some of the symbols for the implementation, so I
compile with -fvisibility=hidden and add
__attribute__((visibility("default"))) to the "class Foo" definintion.

My question is whether the visibility attribute applies to the methods
of the nested impl struct and makes all members visible or whether
they stay hidden.

Thanks,

Paul B.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]