Two-stage name lookup problem

Jakub Pawlewicz jakub.pawlewicz@gmail.com
Wed Oct 26 15:56:00 GMT 2005


I'm confused. I do not want use any pointers and memory allocation. I
wrote a program which is very fast because I was using many inline
templates and no pointers. The program worked find unless I had to
switch to gcc 3.4. In my first post it is important that there are
templates and that I am using non-pointer variable declaration of type
B in function A::f(). Please go back to the original problem.

I don't know template terminology, but I try my best to describe what
the problem is. So please be gentle if I make something wrong.

The declaration of A a; in struct B should be allowed if we are able
to postpone instantiation of struct B, because it is a template
struct. The function A::f() is template also, so maybe we could better
postpone the instantiation of the function body. I don't know how can
I do such things. Before two-stage names lookup there was no problem
with such hacks and now I need a workaround..

2005/10/26, corey taylor <corey.taylor@gmail.com>:
> Jakub,
>
>   The declaration of A a; in struct B because it requires an object
> size.  Using a pointer to an incomplete type is allowed.  You could
> create a new A in the B constructor and assign it to a pointer.
>
>   The other errors center around this.  The question about using B b
> has nothing to do with the error above.
>
> Corey
>
> On 10/26/05, Jakub Pawlewicz <jakub.pawlewicz@gmail.com> wrote:
> > > Your problem is not with templates.
> > >
> > > Here's your problem in a nutshell...
> > >
> > > struct A
> > > {
> > >     int x;
> > >
> > >     struct B
> > >     {
> > >         A a;
> > >     };
> > > };
> > >
> > >
> > > You cannot use A within B, because at that point A is incomplete.
> > >
> > > You can pull B out of A.  If you want B to be in the A namespace, change
> > > 'struct A' to 'namespace A', and make 'struct A_impl', fully declared, and
> > > then use that within 'struct B'.
> >
> > But what about function f(), the member of struct A? I want to declare
> > variable with type B in the body of the function:
> >
> > struct A {
> >     ...
> >     void f()
> >     {
> >         B b;
> >         ...
> >     }
> > };
> >
> > I am aware that kind of code may be ill formed, but when using
> > templates, there should be something like deferred instantiation.
> > Struct B is a template and also function A::f() is a template. Struct
> > B is needed only when function A::f() is used. Struct B should be able
> > to construct member of type A and Struct B do not use function A::f().
> > I want all functions be inline. Any solutions?
> >
>



More information about the Gcc-help mailing list