














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
Generic Algorithms, Print an Array, Arrays of any type, Generic container, Operations, Increment operator, Dereference operator, Class Templates, Facilitates reuse of classes are points you can learn in this Object Oriented Programming lecture.
Typology: Slides
1 / 22
This page cannot be seen from the preview
Don't miss anything!















const int* find( const int* array, int _size, int x ) { const int* p = array; for (int i = 0; i < _size; i++) { if ( *p == x ) return p; p++; } return 0;
}
template< typename T >
T* find( T* array,int _size,
const T& x ) { T* p = array; for (int i = 0; i < _size; i++) { if ( *p == x ) return p; p++; } return 0;
}
template< typename T >
T* find( T* array, T* beyond,
const T& x ) { T* p = array; while ( p != beyond ) { if ( *p == x ) return p; p++; } return beyond;
}
template< typename T >
T* find( T* array, T* beyond,
const T& x ) { T* p = array; while ( p != beyond && *p != x ) p++; return p;
}
template< typename P, typename T >
P find( P start, P beyond, const T& x ) { while ( start != beyond && *start != x ) start++; return start;
}
int main() {
int iArray[5]; iArray[0] = 15; iArray[1] = 7; iArray[2] = 987; … int* found; found = find(iArray, iArray + 5, 7); return 0;
}
template< class T >
class Vector {
private:
int size; T* ptr;
public:
Vector
template< class T >
Vector
size = s; if ( size != 0 ) ptr = new T[size]; else ptr = 0;
}
template< class T >
Vector
const Vector
}
template< class T >
const Vector
=( const Vector
if ( size != 0 ) { ptr = new T[size]; for(int i = 0; i < size;i++) ptr[i] = right.ptr[i]; } else ptr = 0; } return *this;
}