x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

PURE_VIRTUAL method

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?

Product Version: Not Selected
Tags:
more ▼

asked Aug 15 '14 at 06:00 PM in C++ Programming

avatar image

Sleicreider
160 35 33 46

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi Sleicreider,

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.

Tom

more ▼

answered Aug 15 '14 at 06:10 PM

avatar image

thavlik
26 1 4 5

avatar image Sleicreider Aug 15 '14 at 06:18 PM

but using c+ pire virtual functions(virtual void MyMethod() = 0); somehow doesn't work at all in ue4 projects

avatar image thavlik Aug 16 '14 at 12:30 AM

PrimitiveComponent.h line 36 says otherwise.

avatar image bellicapax Nov 07 '18 at 08:06 PM

@thavik I don't know what line/code you're referring to, but that nowhere in that file could I find a pure virtual function.

avatar image Sleicreider Nov 07 '18 at 11:29 PM

@bellicapax

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.

avatar image bellicapax Nov 08 '18 at 12:05 AM

My bad! Thanks for pointing this out. I should make better practice of checking when the answers/comments were left and taking in that context.

avatar image NoelWidmer Aug 23 '16 at 07:50 PM

Every UOBJECT must be isntaniciable in order for UE to create the CDO (Class Default Object) that is why UOBJECTs cannot be abstract. That just hit me hard... See https://answers.unrealengine.com/questions/28225/pure-virtual-methods.html

avatar image Sleicreider Sep 06 '17 at 09:14 AM

oh ._. good to know

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question