Solved

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

Posted on 2007-11-16
6
191 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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

12 Experts available now in Live!

Get 1:1 Help Now