Filter posts by Category Or Tag of the Blog section!

Why should I define container classes in C++

Tuesday, 29 April 2014

What's a container class?

It's a class which is used to hold objects in memory or external storage to clumping variables of the same type to make the sorting, searching, … easier. A container could store many entities and provide direct access to them like string class.  Needless to say, The size of the container depends on the number of the objects it contains. A Container usually defined as a class that gives you the power to store any type of data. A container class acts as a generic holder.

a container class is in two kinds: 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. A simple container class example, I define an array with initialized members:

vector<int> numbers(5);

Now you can define an access to the members of this container:

#include <vector>

using namespace std;

int numbers[]={1, 4 , 4 , 7 , 8 };

int main () {

  vector<int> numbers(numbers, numbers+6);


You can also access the members of this container:



Category: Software

Tags: C++

comments powered by Disqus