Ehsan Ghanbari

Experience, DotNet, Solutions

Why should I define container classes in C++

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:



About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns. I spend a lot of time on software architecture. Since 2008, I've been as a developer for different companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the past years, Read More

Post Tags
Pending Blog Posts
using Elmah in MVC4
Using FluentSecurity in MVC
Strategic design
Factory Pattern
time out pattern in ajax
Redis as a cache server
How to use PagedList In MVC
Multiple submit buttons in MVC
Domain driven design VS model driven architecture
What's the DDD-lite?