Referencing Actor in world using c++

GetAllActorsOfClass is a Blueprint static function, if you want to get all actors of a specific class in C++ you should use TActorIterator, you can see an example in GameplayStatics.cpp under GetAllActorsOfClass function:

TSubclassOf<AActor> ActorClass;
TArray<AActor*> OutActors;
if (ActorClass)
{
	for(TActorIterator<AActor> It((), ActorClass); It; ++It)
	{
		AActor* Actor = *It;
		OutActors.Add(Actor);
	}
}

You can place ActorClass and OutActors where you want, maybe in your header file with UPROPERTY macro to have them accessible from Blueprints or inside a function, it’s your choice!