Template specialization

It seems that the following construct is valid:

1
2
3
4
5
6
7
8
9
10
11
12
13
template<bool b>
class TOTO
{};


template<>
class TOTO<false>
{};

template<>
class TOTO<true>
	: public TOTO<false>
{};


That is, the specialization of a template can use / derive from another specialization of the same template.

What do you think of this?!
1
2
3
TOTO<false>* x = new TOTO<true>; // Will work
TOTO<true>*  y = new TOTO<false>; // Will not
//Happy debugging if you will run into this in your actual project. 
Last edited on
Anyway differently parameterized templates are different types...
So for me this not really an issue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template<bool b>
class TOTO
{};


template<>
class TOTO<false>
{};

template<>
class TOTO<true>
{};

TOTO<false>* x = new TOTO<true>; // Will not work
TOTO<true>*  y = new TOTO<false>; // Will not too 

Your question was about inheritance from different specialization of the same class. If you inherit one from other it will work. And a slight mistake in initialization can mess your program.
Topic archived. No new replies allowed.