c++nested-map

nested map inner value with []


I have a nested map with all self-defined objects as key and values

typedef map <Time,WindLogType> minuteIntervalData;
typedef map <Date,minuteIntervalData> DayData;

How can I access the the data in the inner map by using the operator [] when the inner key is unknown?

Eg.

DayData[date1] //gets time1,time2,time3..... and WindLogType

Solution

  • The only way to access a map (whether it is an "inner" map or otherwise) with operator[] is by passing the key as the operand. Thus if the key is unknown, you cannot access the values with operator[].

    There are other ways to access values of a map though and not all of them require the knowledge of the keys. One way to access the values is to use iterators.