The lecture presents the following code as preventing changes to Actor:
for (const auto& Actor : OverlappingActors)
{
// Use Actor
}
This isn’t the case, since auto is deduced to be AActor*
and const will apply to the outermost type (that is deduced by auto), or the pointer in this case. This means that the type of Actor is Actor* const&
and Visual Studio will show this in a tooltip when hovering over Actor. The corresponding code to make Actor const, would be:
for (const auto* Actor : OverlappingActors)
{
// Use Actor
}
In this case, Actor is deduced to be AActor
and the const applies to AActor, just as it would if you’d typed AActor instead of auto.
There’s a great talk by Scott Meyers about type deduction here.