

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of template specialization, resolution order, function template overloading, and inheritance in object-oriented programming using c++. It covers the concept of template specialization, its derivations, and the resolution order of function calls and template instantiation. The document also explains the rules for using inheritance with templates and the differences between complete specializations, partial specializations, and ordinary classes.
Typology: Slides
1 / 33
This page cannot be seen from the preview
Don't miss anything!


























template< typename T > class Vector { … };
template< typename T > class Vector< T* > { … };
template< > class Vector< char* > { … };
int main() { Vector< char* > strVector; // Vector< char* > instantiated
Vector< int* > iPtrVector; // Vector< T* > instantiated
Vector< int > intVector; // Vector< T > instantiated return 0; }
template< typename T > void sort( T );
template< typename T > void sort( Vector< T > & );
template< > void sort< Vector<char> >( Vector< char > & );
void sort( char* );
int main() { char* str = “Hello World!”; sort(str); // sort( char* )
Vector<char> v1 = {“ab”, “cd”, … }; sort(v1); //sort( Vector<char> & )
Vector
int iArray[] = { 5, 2, 6 , 70 }; sort(iArray); // sort( T )
return 0; }
template< class T > class A { … };
template< class T > class B : public A< T > { … };
int main() { A< int > obj1; B< int > obj2; return 0; }
int main() { A< int > obj1; B< int* > obj2; return 0; }
template< > class B< char* > : public A< T > { … }; // Error: ‘T’ undefined
class B : public A< T > { … }; // Error: ‘T’ undefined
template< class T > class B : public A< T* > { … }
int main() { A< int* > obj1; B< int > obj2; return 0; }
template< class T > class B< T* > : public A< T* > { … };
template< > class B< int* > : public A< T* > { … } // Error: Undefined ‘T’
class B : public A< T* > { … } // Error: Undefined ‘T’
template< class T > class A { … };
template< > class A< float* > { … };