























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
Cursors, Pointer, Container, Aggregate object, Methods of Aggregate object, Traverse the elements, Vector, Generic Algorithm, Contiguous sequence, Containers, Traversal operations are points you can learn in this Object Oriented Programming lecture.
Typology: Slides
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























template< class T > class Vector { private: T* ptr; int size; public: Vector( int = 10 ); Vector( const Vector< T >& ); ~Vector(); int getSize() const;
const Vector< T >& operator =( const Vector< T >& ); T& operator ; T* first(); T* beyond(); T* next( T* );
};
template< class T >
T* Vector< T >::next( T* current )
{
if ( current < (ptr + size) ) return ( current + 1 ); // else return current;
}
int main() {
Vector< int > iv( 3 ); iv[0] = 10; iv[1] = 20; iv[2] = 30; int* first = iv.first(); int* beyond = iv.beyond(); int* found = find(first,beyond,20); return 0;
}
a b c d e f g …
Cursor
int main() {
Set< int > is( 3 ); is.add( 10 ); is.add( 20 ); is.add( 30 ); ET* first = iv.first(); ET* beyond = iv.beyond(); ET* found = find(first, beyond, 20); return 0;
}
template< typename P, typename T > P find( P start, P beyond, const T& x ) { while ( start != beyond && *start != x ) ++start; // Error
return start; }
int main() {
Set< int > is( 3 ); is.add( 10 ); is.add( 20 ); is.add( 30 ); int* found = find( is, 20 ); return 0;
}
a b c d e f g …
Cursor 1 Cursor 2