You can use PURE_VIRTUAL with non-UObjects, but there’s no reason to. I think the idea behind it was stub functions needed to exist for virtual methods so that “pure virtual” would work for BlueprintNativeEvent and other Blueprint-related virtuals.
The PURE_VIRTUAL macro just inserts a runtime assertion that says you shouldn’t ever be executing that block of code, hence why child classes don’t need to override for it to compile, because C++ doesn’t recognize it as a pure virtual method.
It appears that the traditional C++ syntax is preferred in non-UObjects and the macro is actually enforced in UObjects.
AFAIK it’s only possible to create abstract methods using PURE_VIRTUAL instead of virtual void MyMethod() = 0;
But does this PURE_VIRTUAL also work for non UObject classes? & classes without UCLASS() ?
Until now it seems that it’s also possible that child classes don’t need to implement pure virtual methods with this macro.
can anyone help?
He was refering to some older stages of the file from around version 4.4 where you could find /** Defines a triangle by its vertices. */ virtual void DefineTriangle(const TStaticArray<FPrimitiveTriangleVertex,3>& InVertices,const UMaterialInterface* Material) = 0; But seems like they changed some stuff in the file.
You can just check the old code on github if you linked your account.
I am unable to use pure virtual C++ in unreal (I get errors about instantiation). After falling eventually on this thread, I tried to use PURE_VIRTUAL macro instead.
As mentioned by @@anonymous_user_1d769e01, using PURE_VIRTUAL does not force overriding the method it only perform an assert in some situations.
That being said unless you find a way to use pure virtual cpp. I still recommend using PURE_VIRTUAL for 2 reasons:
-1: By seeing the PURE_VIRTUAL macro in your .h you can then understand the intention behind the call.
-2: If someone calls your PURE_VIRTUAL method by accident, you can get ‘Pure virtual not implemented (AYourClass::YourPureVirtualMethod)’ in the crash reporter.
Still a solution that force the overriding of the method would be great.