COSC 2436 - Programming Fundamentals III Data Structures
Bob Comer, Professor of Computer Studies
Example Programs
Chapter 9 - Templates and Standard Comtainers
Description Program A List class template created by:
client program file
listdemo.cpp template header file
DList.h template implementation file
DList.template
This simple example shows how to create and use a vector.
The vector class has a subscript operator
that can be used to access elements in the vector.
However, the subscript operator cannot be used to add elements to the vector.
You must use a member function (like push_back()) to add elements.
Some STL containers do not have a subscript operator.
All STL containers allow you to use iterators to access the elements in the container.
The previous vector example has been rewritten to use iterators.
Since the template implementation must be compiled at the same time as the application,
I had to make sure that my IDE did not try to compile the template implementation twice.
To do this I took the implementation file "DList.cpp"
and renamed it "DList.template".
My IDE will not try to separately compile a file with an extension of ".template".
Return to Programming Fundamentals III Home Page
Copyright: © 2015 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to: Bob Comer
Last updated: April 5, 2015