1

I have kinda simple question, but I couldn't find any specific answer to this. So the question is: Let's say I have a vector with a structures inside. From the searches I have found out, that when we are reading classes in a vector, we should use an const auto&, like this

for (const auto& Class : Classes)

and for something like DWORD vectors it doesn't matter, but my question is, does it make sense to use the const auto& while working with structures? They don't have a constructor, but when using just auto, it should make a copy and make the loop slower, or more unefficient, or not?

Martin Prince
  • 139
  • 1
  • 5

1 Answers1

1

There is no such thing as a structure in C++.

Whether you write struct or class, you have created a class.

The classes created in both cases are equally capable of having a constructor.

So, yes. The advice is the same.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055