Problem with casting

Have you included the header file of the class at the top of the cpp?

yep its all included. theres no red lines under the type. Just whilst I try to use it after casting it.

Can you do a pastebin or something of the code? :slight_smile:

Hey guys I hope someone can help me. I’m having a problem with casting an empty class that has only been declared. I’m following a tutorial that is not very old so it might be something I’m doing wrong but I can’t find a fix. I created a pointer to the declared class so the header file knows what it is. I then try to cast this pointer into UGameplayStatics::GetPlayerPawn(this,0)). The whole entire line is…
PlayerPawn = Cast(UGameplayStatics::GetPlayerPawn(this, 0));
the APawnTank is the created class declared in the header file and I’m trying to cast it to the player pawn.
The cast doesn’t seem to ever be successful and when I try to use PlayerPawn which should’ve been Cast I always get an error. the two errors I get are…

  1. error C2027: use of undefined type ‘APawnTank’

  2. note: see declaration of ‘APawnTank’

I’ve been tryijng to fix it for a few days and I can’t find anything helpful. so any help would be appreciated :slight_smile:

This is also all written in unreal c++ :slight_smile:

whats a paste bin?

A site where you can paste a big chunk of code, save it, and then share it with people: https://pastebin.com/

Hey I think this link will work. I added the .cpp and the .h file

So yea, you need to add the header of the APawnTank file to the top of the PawnTurret.cpp file, like:
#include “PawnTank.h”

thank you so much. I had actually done that before but i got alot of linker errors but I have now redone it and fixed the linker errors. I had declared the constructor but not put it in the .cpp file. Thanks so much, I’d been stuck for days :)))))