Posts

Showing posts with the label Template classes

Templates in C++

An introduction to using template classes in C++, that starts extremely simply and builds up from there...

Printing the contents of STL containers in a generic way

A generic Print function A way of using STL algorithms combined with template functions as a means of printing the contents of any type of STL container (eg a std::vector ), containing any generic data type (eg int , std::string etc). typename T defines the generic data type held by the container, while typename InputIterator describes the STL container iterators passed to it:

Using Template Classes to Handle Generic Data Types in STL Containers

Image
A code snippet with which utilizes both template classes and STL to handle generic data types. In keeping with the spirit of this blog, I have kept the explanation to a minimum and hopefully the code posted below should be self-explanatory.  The idea is for readers to get the gist of what I am saying so that they can go off and make up more relevant examples of their own.