How to cast correctly?

I make it simple and post only an simplified example of what im trying to do.

YourCharacter.cpp

#include Weapon.h

void AYourCharacter::TakePickup()
{
    AWeapon* Weapon = Cast<AWeapon>() <------- How to do it correctly?
  {
       WeaponM4->DoSomething();
  }

}
Weapon.cpp

 AWeapon::AWeapon
{
    WeaponM4 = CreateDefaultsuboject<UStaticMeshComponent>();
}


void AWeapon::WeaponFunction()

{
         Do something();           
}

So as you can see, i want to call the function from the Weapon.cpp script whenever i the character picks it up.

Any ideas how to do this correctly? Thanks already!

You should provide a pointer to Cast function, in your example you don’t cast anything to AWeapon. Example:

void AMyActor::Foo()
{
    AWeapon* const pWeapon = GetCurrentWeapon();
    if(AShootingWeapon* const pShootWeapon = Cast<ASoothingWeapon>(pWeapon))
    {
      pShootWeapon->Shoot();
    }
}