lets say i have some code
how could I get Inner to be the default argument for the template?Code:template <class Type1, class Type2 = ???>
class Outer
{
class Inner
{};
};
Printable View
lets say i have some code
how could I get Inner to be the default argument for the template?Code:template <class Type1, class Type2 = ???>
class Outer
{
class Inner
{};
};
Try giving it a forward declaration outside the class, perhaps.
Code:class Outer::Inner;
template <class Type1, class Type2 = Inner>
class Outer
{
class Inner
{};
};
Never mind... that failed horribly... I'll see if I can figure it out though.
You might be able to get:
class Outer;
class Outer::Inner;
class Outer { //...
to work.
I tried many variations on that with GCC to no avail (nothing quite like guess-n-check programming, eh?).
To be honest, I'm not entirely sure its possible. Since something inside the class is would be responsible in part for defining its own type, the logic seems like it'd become circular to have Inner as a valid template argument.
Heres my rationale (anyone, feel free to shoot holes in this, I'm just trying to reason my way through this):
You have four types, A1, A2, B1, B2.
Outer<A1, A2> is a different type from Outer<B1, B2>, and consequently, Outer<A1, A2>::Inner is a different type from Outer<B1, B2>::Inner. Therefore, the type Outer::Inner is incomplete, and therefore, cannot fully define another type. It would be valid to have Outer<A1, A2>::Inner as one of the template parameters, but not Outer::Inner.
Consider this:
You have Outer<T1, Inner>. Inner is of course (as it is completely defined) Outer<T1, Inner>::Inner, so your declaration is something like this:
Outer<T1, Outer<T1, Outer<T1, ... ad infinitum ...>::Inner>::Inner>, which clearly doesn't work.
Anyways, I may be totally off, but it seems to make sense (at the moment at least).
Cheers
That makes sense, thanks.