Solved

[noob][c++]  what is a container?

Posted on 2007-11-16
6
192 Views
Last Modified: 2010-04-01
what is a container?
0
Comment
Question by:Troudeloup
6 Comments
 
LVL 14

Assisted Solution

by:cuziyq
cuziyq earned 100 total points
ID: 20299637
A container is a set of data wrapped up in a class.  A linked list is an example of a container class.
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 250 total points
ID: 20299657
A container is a class that stores multiple objects of the same type.
0
 
LVL 30

Accepted Solution

by:
Axter earned 250 total points
ID: 20299666
Example containers:
std::vector
std::list
std::deque
std::map
std::set

Some would also consider std::string a container.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 150 total points
ID: 20299695
To add to above information:

By using template containers you can store any arbitrary type. The most used container class is std::vector which is a dynamic array class. A special and very useful container is std::map whic is a so-called dictionary. A dictionary has a key and data type, which were stored as a pair. A dictionary provides a fast access to the data via the key.

Regards, Alex
0
 
LVL 30

Expert Comment

by:Axter
ID: 20300263
FYI:
Many developer make the mistake of using std::list as they're default container.
For most requirements std::vector is more efficient then std::list.
Moreover, the C++ standard recommends using std::vector as the default container.

In general, std::list should only be used when you need to remove or add content from the center of the container.

std::deque should be used if you need to add or remove content from the start (beginning) of the container, but don't need to add/remove content from the center.

std::vector should be the default container, since for most requirements, you only need to add/remove content from the end of the container.

Some experts recommend using std::vector, even when you need to add/content from the start or middle of the container when the add/remove action is not accessive.
0
 

Author Comment

by:Troudeloup
ID: 20300540
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now