SLIDE 20 Static Polymorphism Special Issues with Templates
Dependent Base Classes
template<typename T > c l a s s DD : p u b l i c Base< T > { p u b l i c : void f ( ) { b a s e f i e l d = 0; // (1) would l e a d to type r e s o l u t i o n and b i n d i n g to i n t . } }; template< > c l a s s Base<bool> { p u b l i c : enum { b a s e f i e l d = 42 }; // (2) Template s p e c i a l i z a t i o n wants to // d e f i n e v a r i a b l e d i f f e r e n t l y . }; void g (DD <bool> & d ) { d . f ( ) // (3) C o n f l i c t }
1 In the definition of class DD, the first access to basefield in f() would lead to
binding basefield to int (because of the definition in the class template).
2 Subsequently, however, the type of basefield would be modified into
something unchangeaoble for the type bool.
3 In the instantiation (3) a conflict would then occur.
Ole Klein (IWR) Object-Oriented Programming
20 / 48