A question about PURE_VIRTUAL functions.

Am I supposed to get a warning if I don’t implement a PURE_VIRTUAL function in a child class? I’ve created

UFUNCTION()
virtual void Terminate() PURE_VIRTUAL(AMyTestClass::Terminate, ;)

I’ve not implemented it and I’d expect to get Pure virtual not implemented in the output log but I don’t.

Hi GlacierFox,

Have you defined the class as abstract?

UCLASS(abstract)

Hi, yes I’ve done that. The thing is, it actually works like a pure virtual function if I was to define it inside a child class - so that’s all good, it allows me to build without actually defining it in the .cpp.

However, if I don’t define it and simply designate it as PURE_VIRTUAL I’d expect a warning or compilation error but it seems to build fine and and play fine.

Just curious as to if I’m doing something incorrectly as I’ve read from other posts I’m supposed to be getting a warning similar to standard C++.

I’ve never actually not derived a pure virtual so haven’t seen any errors either, but having a look at the macro, it does seem to throw an error - but needs defined CHECK_PUREVIRTUALS:

#if CHECK_PUREVIRTUALS
#define PURE_VIRTUAL(func,...) =0;
#else
#define PURE_VIRTUAL(func,...) { LowLevelFatalError(TEXT("Pure virtual not implemented (%s)"), TEXT(#func)); __VA_ARGS__ }
#endif

I just tried adding this to my code and compiling, and didn’t get any errors, it seems to only be defined in Build.h so I’m thinking adding that to your project will fix it:

#if CHECK_PUREVIRTUALS
something to generate an error....
#endif
2 Likes

This works. Thanks for taking the time to help me with this. Appreciate it.

2 Likes

sorry for bumping this old post. can someone elaborate more on how to apply or set CHECK_PUREVIRTUALS