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?
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With