A container stores many entities and provide sequential
or direct access to them. List, vector and strings are such containers in standard template library. The string class is a container that holds chars. All container classes access the contained elements safely and efficiently by using iterators.
Container class is a class that hold group of same or mixed objects in memory.
It can be heterogeneous and homogeneous. Heterogeneous container class can hold mixed objects in memory whereas when it is holding same objects, it is called as homogeneous container class.
Example for Container Class
An array Create a header file (IntArray.h) #ifndef INTARRAY_H #define INTARRAY_H class IntArray { }; #endif
An array container class http://www.learncpp.com/cpp-tutorial/104-container-classes/ Create constructors for initialization of variables used in the container.
Use of Assert Assert is a macro which is useful to check certain conditions at run time (when the program is under execution) . To use it the header file assert.h should be included in the program
Here it is used to check the index to make sure it is valid. assert(nIndex >= 0 && nIndex < m_nLength);
If this condition is true then the program continues otherwise program terminates with an error message
An array container class http://www.programmingsimplified.com/c/source-code/assert #ifndef INTARRAY_H #define INTARRAY_H #include <assert.h> class IntArray { private: int m_nLength; int *m_pnData;