Class and Container

M

Michael

Hi,

In real world, when to use class, container, class & container? It
seems to me that container is more useful to number chain, class is for
implementing complex porjects? Right? Please give your insights.

Thanks in advance,
Michael
 
A

Alf P. Steinbach

* Michael:
In real world, when to use class, container, class & container? It
seems to me that container is more useful to number chain, class is for
implementing complex porjects? Right? Please give your insights.

In C++ a container is a class.
 
M

Michael

Alf said:
* Michael:

In C++ a container is a class.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Sorry for not clarifying my questions. I would like to know when shall
I create my own class or use STL container?

Thanks,
 
A

Alf P. Steinbach

* Michael:
> [quoting signature]]

Please don't quote signatures -- corrected.


* Michael:
Sorry for not clarifying my questions. I would like to know when shall
I create my own class or use STL container?

Should you choose the blonde or the brunette, that's the question.
Well, if you absolutely feel you have to choose one or the other, try
both, and choose the one that pleases you the most, or, be more
pragmatic and choose both. ;-) Seriously.

Generally the purpose of a class is to maintain a class invariant, a set
of relationships between the instance data members. The class invariant
is established by the class' constructor and maintained by every public
member function.

If a standard container doesn't give you the class invariant you want,
then a custom class is called for.
 
O

osmium

Michael said:
In real world, when to use class, container, class & container? It
seems to me that container is more useful to number chain, class is for
implementing complex porjects? Right? Please give your insights.

You write your own class when you can't find an STL container that does what
you want. Hideously complex projects can be done with just the STL and C++
or even just C++ or even just C so complexity is of no use as a metric. .
 
D

Daniel T.

Michael said:
In real world, when to use class, container, class & container? It
seems to me that container is more useful to number chain, class is for
implementing complex porjects? Right? Please give your insights.

Maybe if you gave some examples where you think either a class or
container could be used, and we can tell you what we would use in that
situation.
 
D

David Harmon

On 5 Aug 2006 10:34:34 -0700 in comp.lang.c++, "Michael"
Sorry for not clarifying my questions. I would like to know when shall
I create my own class or use STL container?

I prefer to use the STL container classes whenever they fulfill the
requirements of the program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top