public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Two-stage name lookup problem
@ 2005-10-26  7:18 Jakub Pawlewicz
  2005-10-26 12:47 ` John Love-Jensen
  2005-10-27 12:22 ` Jakub Pawlewicz
  0 siblings, 2 replies; 9+ messages in thread
From: Jakub Pawlewicz @ 2005-10-26  7:18 UTC (permalink / raw)
  To: gcc-help

I have problem with templates and I need a solution. I want to use
inner class B with a member of outer class A type. Then I wand class A
to use template class B in function f. Here is code I want to change
in order to compile with gcc 3.4. It compiles fine with gcc 3.3.

struct A {
 int x;
 A(int x) : x(x) { }

 template <int X>
 struct B {
   A a;
   B() : a(X) { }
   void f() { }
 };

 template <int X>
 void f()
 {
   B<X> b;
   b.f();
 }
};

int main()
{
 A a(0);
 a.f<0>();
}

Compilation fails with a message
a.cpp:7: error: field `a' has incomplete type
a.cpp: In constructor `A::B<X>::B()':
a.cpp:8: error: class `A::B<X>' does not have any field named `a'

Is there any workaround?

Thanks in advance

Jakub Pawlewicz

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Two-stage name lookup problem
@ 2005-10-26 13:57 Brian T. Brunner
  0 siblings, 0 replies; 9+ messages in thread
From: Brian T. Brunner @ 2005-10-26 13:57 UTC (permalink / raw)
  To: gcc-help


The a of type A contains a B, which includes another a of type A which in turn includes a B...
I can't imagine this not being an infinite recursion at the data object creation level.

If B contains a pointer to an object of type A, then we should be OK.

Brian Brunner
brian.t.brunner@gai-tronics.com
(610)796-5838

>>> John Love-Jensen <eljay@adobe.com> 10/26/05 08:47AM >>>
Hi Jakub,

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'.

HTH,
--Eljay


*******************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept
for the presence of computer viruses.

www.hubbell.com - Hubbell Incorporated

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-11-05 19:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-26  7:18 Two-stage name lookup problem Jakub Pawlewicz
2005-10-26 12:47 ` John Love-Jensen
2005-10-26 14:07   ` Jakub Pawlewicz
2005-10-26 14:43     ` corey taylor
2005-10-26 15:56       ` Jakub Pawlewicz
2005-10-26 16:20         ` corey taylor
2005-11-05 19:35   ` Nathan Sidwell
2005-10-27 12:22 ` Jakub Pawlewicz
2005-10-26 13:57 Brian T. Brunner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).