C++ - Why are pointers used so much?

AndreSchreiber
Sun, 24 Aug 2014 17:28:47 +0000
C++

Okay, this may seem like a strange question, but why are pointers used so much in unreal engine? I am new to programming in C++, and come from Java/C#. I have read repeatedly that you should avoid pointers and use references and values instead, so why are they used so much in the engine. There must be a reason for this. For example:

AActor* UWorld::SpawnActor
(
    UClass*         Class,
    FName           InName,
    FVector const*  Location,
    FRotator const* Rotation,
    AActor*         Template,
    bool            bNoCollisionFail,
    bool            bRemoteOwned,
    AActor*         Owner,
    APawn*          Instigator,
    bool            bNoFail,
    ULevel*         OverrideLevel,
    bool            bDeferConstruction
)

Why does this return a pointer (and not a value) and take in so many pointer arguments and not reference arguments.

EDIT - So basically references (const) are used when by value would be less efficient to copy, but cannot be null; and pointers are used when passing by value is inefficient and null is an option. Also should I use nullptr or NULL in the engine? Also, why is the actor returned as pointer, not value?

Thank you

7 posts - 1 participant