This is the mail archive of the gcc-help@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]

visibility and nested classes - im a bit confused


Hi eveybody!

I ran into a very strange compilation error because gcc-4.2.1 has very
strict rules. Unfortunately in this case the error message wasn't too
informative.

        template <class T> class ATemplate
        {
            public:
                class Foo
                {
                    Foo(ATemplate<T> t){
                        /*ATemplate::*/Bar *undeclared = new /*ATemplate::*/Bar;
                    };
                };

            private:
                struct Bar
                {
                    Foo *f;
                    Bar *b;
                };
        };


* Problem

When I tried to compile this file, gcc said that the error: undeclared
was not declared in this scope. I assumed that the Bar not declared
yet or the inner class cannot see it so I need to declare or make it
visible by the using keyword. It didn't help, it an other kind of
problem.

* Solution

I emoved the ATemplate name qualification, because we are already in
the scope of ATemplate.
At this point I'm a little bit confused:

>From a point of view, a block can see the symbols which are declared
in the block, or in the surrounding blocks. This means that all the
symbols which are declared in the ATemplate are visible in the Foor,
as we are in the scope of ATemplate

On the other hand, although, as fat as I know the inner classes
doesn't have any pointer to the surrounding classes, so a variable
defined in the outer class, cannot be accessed from the inner class,
so it not true that everything is visible...

Or this is also a difference between definition and declaration?

Can anybody explain how does it exactly works?

Best regards:
Tibor


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