

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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* > { … };