This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Two-stage name lookup problem
- From: Jakub Pawlewicz <jakub dot pawlewicz at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 27 Oct 2005 14:21:56 +0200
- Subject: Re: Two-stage name lookup problem
- References: <33b23e0c0510260018h6f75cd10l@mail.gmail.com>
I found a workaround. It looks ugly, but it works. I used dummy
template arguments to overcome instantiation. I hope somebody will
find a nicer solution. Here is a hacked code:
template <typename Dummy> struct A_impl;
typedef A_impl<void> A;
template <typename Dummy>
struct A_impl {
int x;
A_impl(int x) : x(x) { }
template <int X, typename Dummy2>
struct B {
A_impl<Dummy2> a;
B() : a(X) { }
void f() { }
};
template <int X>
void f()
{
B<X, Dummy> b;
b.f();
}
};
int main()
{
A a(0);
a.f<0>();
}
2005/10/26, Jakub Pawlewicz <jakub.pawlewicz@gmail.com>:
> 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
>