Need some help with the use of certain keywords.

Hey Guys! I’m new to game c++. I’m getting acquainted with it by following along with different c++ examples.

What I’m gonna ask might sound pretty lame to some of the programmers, but i’m getting confused by the use of the const keyword.

For eg: right now I’m following along with the Fps C++ tutorial from wiki.


void AFPSProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
   {
       if ( OtherActor && (OtherActor != this) && OtherComp )
       {
           OtherComp->AddImpulseAtLocation(ProjectileMovement->Velocity * 100.0f, Hit.ImpactPoint);
       }
   }

Please help me out. Above is an example from the project.

As far as I know. I think Hit is a reference to a constant vector. So, whatever location we achieved during the execution of the event we cannot change it. Is that right?

But we can change hit?

Please help. Thank you.

Correct. The const keyword when applied to an argument in this way says that the function takes a constant parameter which won’t be changed by the function.

So you can read from the vector and copy it, but you can’t change any of it’s data. In fact, if you try to the compiler will error.