nested class in template class

Oct 23, 2009 at 1:41pm
Hi,

Can somebody help me, that what's the problame with that code?

1
2
3
4
5
6
7
8
9
10
11
12
template <typename T>
class A
{
     class B {};	
	
     B f(void);
};

template<typename T>
A<T>::B A<T>::f(void)
{
}



Oct 23, 2009 at 2:05pm
B is private in A as you've written it.
Oct 23, 2009 at 2:49pm
Thx for answer, but it's not about visibility.

If I write it without template :
1
2
3
4
5
6
7
8
9
10
class A
{
    class B {};
    B f(void);
};


A::B A::f(void)
{
}


It works.

The compiler says:
" teszt.cpp:16: error: expected constructor, destructor, or type conversion before 'A' "

It's something that I don't know how to refer to B when A is template.
Oct 23, 2009 at 3:18pm
To compile that, the compiler must know the constructor, destructor and size of B.
Oct 23, 2009 at 11:49pm
I found the answer, it should be:

1
2
3
4
5
6
7
8
9
10
11
template<typename T>
class A
{
    class B {};
    B f(void);
};

template<typename T>
typename A<T>::B A<T>::f(void)
{
}

Topic archived. No new replies allowed.