0

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
4
  • 1
    The key part in your question is "when the inner key is unknown". If you want to access a single element of the nested map (for example using the [] operator), you must know its key. You can still use the map, like for example iterate over it, but it's not possible to get a single element of it. Commented Nov 18, 2020 at 3:54
  • I'm not sure I understand. You have a key (a Date) to the outer map? From that you get a map of type minuteIntervalData. From that you want to get all entries in that map? (If so, why mention the outer map at all? Just start with a single minuteIntervalData object.) Commented Nov 18, 2020 at 3:55
  • @JaMiT In my (Date) i have several dates 1/01/2020,2/01/2020 from the dates i want to access the inner map which contains time stamps of the day eg. 9:30,9:40. From there i want to access a Date and get all the timestamps according to the Date key Commented Nov 18, 2020 at 4:02
  • @Boom Think abstractly, and simplify. You appear to know that, given an object days of type DayData, the expression days [date1] evaluates to an object of type minuteIntervalData. Done deal. For the next step, abstract away that expression and start with an object of type minuteIntervalData. Once you have such an object, it does not matter how you obtained it. You can remove all mention of DayData from your question, if I understand what you are trying to ask. Commented Nov 19, 2020 at 1:44

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.