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"

New error in 4.8 -- C2512: no appropriate default constructor available

I have a class derived from AActor and it contains a member that does not have a default constructor, i.e.:

 #include "GameFramework/Actor.h"
 #include "MyActor.generated.h"
 
 UCLASS()
 class MYGAME_API AMyActor : public AActor
 {
     GENERATED_BODY()
 
 public:
 
     AMyActor();
 
     some_other_class x;  // some_other_class has no default constructor!
 };

But I initialize "x" accordingly in the CPP file:

 #include "MyGame.h"
 #include "MyActor.h"
 
 AMyActor::AMyActor() :
     x(0, 0, 0) // must pass parameters to some_other_class constructor
 {
     // Initialize AMyActor...
 }

This worked as it should in 4.7 but in 4.8 I'm getting this error:

1>C:\Projects\MyGame\Intermediate\Build\Win64\UE4Editor\Inc\MyGame\MyGame.generated.cpp(502): error C2512: 'some_other_class' : no appropriate default constructor available

The problem line in the generated code is this:

 DEFINE_VTABLE_PTR_HELPER_CTOR(AMyActor);
Product Version: UE 4.8
Tags:
more ▼

asked Aug 16 '15 at 07:06 PM in C++ Programming

avatar image

Pat-Level17
70 6 12 126

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

1 answer: sort voted first

Hello, Pat-Level17

I am sorry to hear about your problem. Please note that in 4.8 the way virtual pointers are obtained for UClasses was changed, so that special empty constructor is used to get it. Special virtual table helper constructor is generated automatically for most cases, but sometimes it's not possible (for example when there is no default constructor for members types). In this situation, there is a possibility to override the generated constructor and write a custom one like this:

 UCustomClass::UCustomClass(FVTableHelper& Helper)

(Constructor of the base class needs to be called with the same parameter.)

Please note that this constructor should not be used for anything else since there is no guarantee the object will be in correct state after calling it.

Thus, to fix the problem, you can add something like this to your code:

 AMyActor(FVTableHelper& Helper)
      : Super(Helper),
        x(0, 0, 0) 
     {
     }

Hope this helped!

Cheers!

more ▼

answered Aug 17 '15 at 07:51 AM

avatar image

Andrii Melnyk
1.9k 60 20 112

avatar image Pat-Level17 Aug 17 '15 at 11:25 PM

That fixes it. Thank you.

This is kind of an awkward thing to have to do, but it works.

(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