

















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
This document from docsity.com covers various advanced topics in object-oriented programming (oop) using c++. It explains member templates, their parameterization, template specializations, partial and complete specializations for classes and functions, and non-type parameters with default values. The document also includes examples and usage of these concepts.
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















class ComplexSet { … template< class T > insert( Complex< T > c ) { // Add “c” to the set } };
int main() { Complex< int > ic( 10, 5 ); Complex< float > fc( 10.5, 5.7 ); Complex< double > dc( 9.567898, 5 ); ComplexSet cs; cs.insert( ic ); cs.insert( fc ); cs.insert( dc ); return 0; }
template< class T > class Vector { }; template< class T > class Vector< T* > { };
template< class T, class U, class V > class A {}; template< class T, class V > class A< T, T, V > {}; template< class T, class U, int I > class A< T, U, I > {}; template< class T > class A< int, T, 5 > {};
template< class T, class U, class V > class A {}; template< > class A< int, char*, double > {};
template< > bool isEqual< const char* >( const char* x, const char* y ) { return ( strcmp( x, y ) == 0 ); }
int main() { int i, j; char* a, b; Shape *s1 = new Line(); Shape *s2 = new Circle(); isEqual( i, j ); // Template isEqual( a, b ); // Complete Sp. isEqual( s1, s2 ); // Partial Sp. return 0; }
template< class T > Array
int main() { Array< char > cArray( 10 ); Array< int > iArray( 15 ); Array< double > dArray( 20 ); return 0; }