I’m pretty sure this is a syntax issue, not a structural issue, but I’ve implemented an abstract base class, and I’m struggling to figure out how to override virtual methods with actual content in classes that inherit from it.
The base, abstract class, extended from UActorComponent and created with the abstract keyword in the UCLASS macro, and a single virtual function Attack(), meant to be overridden.
UCLASS( ClassGroup=(Custom), abstract )
class CODEPROJECT_API UIMorpheme : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UIMorpheme();
virtual void Attack() { check(0 && "You must override this"); };
// virtual TArray<AGround*> MyFunc() { check(0 && "You must override this"); return TArray<AGround *>(); } EXAMPLE OF HOW TO RETURN VALUE WITH ABSTRACT
// Called when the game starts
virtual void BeginPlay() override;
// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
};
This compiles fine, so I was under the impression that I declared and configured it correctly. The next step is to make a class that inherits from UIMorpheme, and attempt to override virtual void Attack() with functionality:
.h:
UCLASS()
class CODEPROJECT_API UIMorphemeVerb : public UIMorpheme
{
GENERATED_BODY()
void Attack();
};
.cpp:
#include "CodeProject.h"
#include "IMorphemeVerb.h"
void Attack(){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Attack() function triggered!"));
}
I thought this was formatted correctly as well, but it creates three errors that I’m having an awful lot of trouble deciphering:
Error IMorphemeVerb.cpp.obj : error LNK2001: unresolved external symbol "private: virtual void __cdecl UIMorphemeVerb::Attack(void)" (?Attack@UIMorphemeVerb@@EEAAXXZ)
Error MVAttack.cpp.obj : error LNK2001: unresolved external symbol "private: virtual void __cdecl UIMorphemeVerb::Attack(void)" (?Attack@UIMorphemeVerb@@EEAAXXZ)
Error CodeProject.generated.cpp.obj : error LNK2001: unresolved external symbol "private: virtual void __cdecl UIMorphemeVerb::Attack(void)" (?Attack@UIMorphemeVerb@@EEAAXXZ)
Assuming it’s kosher to make an actorcomponent virtual (which I’m assuming it is), I’m really hoping that my problem is sloppy syntax, but I can’t see where I would’ve futzed up.