Re: Redefining nested class on class specialization.
Andrey Tarasevich wrote:
Victor Bazarov wrote:
...
I believe you're confusing full specialisation with partial. A full
specialisation is *not* a template. A partial specialisation is
still a template. Try specialising your F::f for, say, all pointers.
...
Well, it is perfectly possible to specialize 'F::f' for all pointers
(referring to the parameter of the enclosing class template). The
question is whether it will work without providing a definition for
the outer class template, which is what the OP's question is really
about. I believe that in C++ this is simply not allowed. It is OK for
explicit specialization, but not allowed for partial specialization.
In order to make the original code compile th OP'd have to
"re-declare" the partially specialized outer classes
template <typename , int > class Outer {
public:
class Inner;
};
template <int i> class Outer<int, i> {
public:
class Inner;
};
template <int i> class Outer<int, i>::Inner {};
template <int i> class Outer<double, i> {
public:
class Inner;
};
template <int i> class Outer<double, i>::Inner {};
The above will compile. I don't now right away whether what appears as
"repetitive" declaration of 'Outer' can be avoided somehow.
The problem is, most likely, that the OP wanted the rest of the "outer"
template to remain intact and only provide the "custom" implementation
of the inner class ('Inner') for a particular [partial] specialisation
of the 'Outer'. That's what seems impossible (prohibited). One would
need to make copies of all original implementation when defining the
partial specialisation of 'Outer' (to keep it intact), or reimplement
it all using containment or private inheritance, to reuse the code...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask