How can I declare and define an inner class within a class template?
Without template I got it to work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
//==== declarations
struct Outer {
struct Inner;
Inner fnc_outer();
};
struct Outer::Inner {
void fnc_inner();
};
//=== definitions:
Outer::Inner Outer::fnc_outer() { return Inner(); }
void Outer::Inner::fnc_inner() { /* do something */ }
int main()
{
Outer o;
o.fnc_outer().fnc_inner();
}
// This works fine.
|
But how do I nest the inner class into a class template?
This doesn't work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
//=== declarations
template <typename T>
struct Outer {
struct Inner;
Inner fnc_outer();
};
template <typename T>
struct Outer<T>::Inner {
void fnc_inner();
};
//=== definitions:
template <typename T>
Outer<T>::Inner Outer<T>::fnc_outer() { return Inner(); }
template <typename T>
void Outer<T>::Inner::fnc_inner() { /* do something */ }
int main()
{
Outer<int> o;
o.fnc_outer().fnc_inner();
}
// What's wrong with this example?
|
Here i get this error message:
1 2 3 4 5
|
14:1: error: missing 'typename' prior to dependent type name
'Outer<T>::Inner'
Outer<T>::Inner Outer<T>::fnc_outer() { return Inner(); }
^~~~~~~~~~~~~~~
typename
|
What does it mean?
Thanks for help.
Last edited on
Thank you both. The link was illustrative to me!