Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of associative array?

I'm reading The C++ Standard Library: A Tutorial and Reference book. In map example:

   typedef map<string,float> StringFloatMap;
   StringFloatMap coll;

   //insert some elements into the collection
   coll["VAT"] = 0.15;
   coll["Pi"] = 3.1415;
   coll["an arbitrary number"] = 4983.223;
   coll["Null"] = 0;

The author say:

Here, the index is used as the key and may have any type. This is the interface of an associative array. An associative array is an array in which the index may be of an arbitrary type.

Any one could explain me, what arbitrary type means in associative array?

like image 945
Milad Khajavi Avatar asked Mar 06 '13 14:03

Milad Khajavi


1 Answers

Arrays are generally indexed by the position of the elements. A simple array - int x[10], has its elements x[0] ... x[9]. The index is an unsigned integral value.

The associative container means that the index can be, well, an arbitrary (not necessarily an unsigned integral) type (in this case, an std::string).

like image 175
Luchian Grigore Avatar answered Nov 16 '22 03:11

Luchian Grigore