How to access variables from another class in ue4 c++

You have to specify the object that you are calling the incrementCounter function on. If you add the following in place of line 36 you should be able to compile without running into the error you mentioned.

UWorld* WorldRef = GetWorld();
AMyFPSGameCharacter* CharacterRef = Cast<AMyFPSGameCharacter>(World->GetFirstPlayerController()->GetCharacter());
if (CharacterRef)
{
	CharacterRef->incrementCounter();
}