Download

Problem with typecasting using 'Cast'

I’m working on creating team-based spawn points and I’ve written a new overloaded ChoosePlayerStart() function. The function needs to typecast the input Player parameter to my derived Team Player class.

The code is as follows:


AActor *AMyGameMode::ChoosePlayerStart (AController *Player)
{
   ATeamPlayer *TeamPlayer = Cast<ATeamPlayer> Player;

...blah...


The compiler complains about the typecast with "error: address of overloaded function ‘Cast’ does not match required type of ‘ATeamPlayer’ ". ATeamPlayer is derived from ACharacter. What’s wrong?

Never mind. Found the problem. Missing ( ) around Player.

The compiler is giving you the wrong error because it thinks you’re trying to take the address of the Cast<> function itself, rather than call it. You forgot the parentheses around the Cast<ATeamPlayer>(Player).

Edit: You figured it out while I was typing the post, good job.