P
P
prosto_anton2014-08-05 09:48:04
C++ / C#
prosto_anton, 2014-08-05 09:48:04

How to organize a for in loop in c++? Is it possible at all?

Spoiled JS, I returned to the pros, which I didn’t really know. I really want to bypass the properties of an object in a loop. So far, this seems to me only in the form of creating an array of properties.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2014-08-05
@prosto_anton

C ++11 introduced this feature:

int a[] = { 1, 2, 3 };
for (int &i : a)
{
  std::cout << "Test new for :" << i << std::endl;
}

N
Nikolay Nozdrin-Plotnitsky, 2014-08-05
@scientistnik

Nanny, I ate with them . What does bypass mean?
Let's go around all your human qualities in a cycle.

T
tsarevfs, 2014-08-05
@tsarevfs

Perhaps you should use std::map to store the properties of an object if they are of the same type (double in this example). If you are talking about iterating over all the fields of the class, then this cannot be done, because they can be of different types and it is not clear what to do with them.
And why do you need it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question