Cannot Call Function After Cast C++

Hello All!
I am currently trying to call a function after casting to my PlayerController class from my Character. Here is my code:
The Character cpp:

AInGamePlayerController * APC = Cast<AInGamePlayerController>(this);

   if (&APC) {
   GLog->Log("Casting To PlayerController Working");
   APC->HandleDeath();
   }
   else {
  GLog->Log("Casting To PlayerController Not Working");
  }

Everything works fine until I get to the point of adding:

APC->HandleDeath();

where I get the error:

error LNK2019: unresolved external symbol "public: static void __cdecl AInGamePlayerController::HandleDeath(void)" (?HandleDeath@AInGamePlayerController@@SAXXZ) referenced in function "public: void __cdecl AInGameCharacter::DoDeath(void)" (?DoDeath@AInGameCharacter@@QEAAXXZ)

Here is the code from my PlayerController:

.h
    public:
        static void HandleDeath();

.cpp
    void HandleDeath() {
    GLog->Log("PC DEATH!!");
    }

Thanks for any help.

If you are casting in your Character class, your first line is wrong. You are trying to cast your character class, not your controller class there. Just put Controller instead of this in the argument for cast in the first line. So do this:


AInGamePlayerController * APC = Cast<AInGamePlayerController>(Controller);

That should work.

I don’t know what exactly is the problem, but I’d change two things and if the error is not gone, post here again:

if (&APC) {

I did not know this could compile. You are asking if the address of the pointer APC is true.
That is always true.
Make this

if (APC) {

or even better, give your pointers a “p” and use the complete question:

if (pAPC != nullptr) {

This is static:

  static void HandleDeath();

If you really want it to be static, then you don’t need a pointer and no casting, just use

PlayerController::HandleDeath() 

in your code.
But I don’t think it should be static at all. I am not sure, I just think it should not be static.

as mentioned below, remove the static keyword

Thanks for your answer. I am still learning and don’t know much about how to correctly use pointers and static functions. The code compiles fine, it just has an issue with:
APC->HandleDeath();

Commenting out this line will fix the compile error.
I have also tried AInGamePlayerController::HandleDeath(); with the static keyword and this also throws an error.
I am able to call variables from the controller and print that to the log, just tried with an int32 variable. Its just the function that can’t be called for some reason.

Ok. Without changing anything except what I mentioned in the comment to the other answer; it is now working. I have no idea how, it just is. I restarted VS and installed VAX. Honestly; I have no idea why its now working.

Remove static keyword