class definition

S

salmon2000

Hi
I am a beginner to c++, I wondered how I can define a class similar to
the c++ standard map class but allow for different type of values to
be stored in the same map?

Thanks!
 
A

Attila Feher

salmon2000 said:
Hi
I am a beginner to c++, I wondered how I can define a class similar to
the c++ standard map class but allow for different type of values to
be stored in the same map?

With many years of learning or by using the boost::any type. See
http://www.boost.org
 
T

tom_usenet

Hi
I am a beginner to c++, I wondered how I can define a class similar to
the c++ standard map class but allow for different type of values to
be stored in the same map?

Are these types related? If they are, you are best off using a base
class (interface) and different derived implementations. e.g.

std::map<int, base*> mymap;

If the values are completely unrelated types (why are they in the same
map then?), then you can use boost::any as already mentioned.

Tom
 

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
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top