Declaring a TCircularBuffer field in a UCLASS causes compiler error C2512 in 4.9 release

The generated code for a UCLASS appears to require a default constructor for the class’ fields, which TCircularBuffer does not provide. I’m able to add a default constructor to the class to fix this problem, but it makes my code less portable, and users of standalone ue4 binaries aren’t able to make a fix like that. It’s not a huge pain since heap allocation would also solve this, but I’m curious what the intended use of TCircularBuffer is.

Thank you.

TCircularBuffer requires a capacity during construction. A parameter-less default constructor does not make sense for this class. If you’re writing a UCLASS that holds a TCircularBuffer, then you must specify a default constructor for your class that correctly initializes the buffer in its initialization list.

Use the GENERATED_BODY instead of GENERATED_UCLASS_BODY macro. For example:

UCLASS()
class UMyObject : public UObject
{
    GENERATED_BODY()
public:
    UMyObject()
        : Buffer(128)
    { }
private:
     TCircularBuffer<int32> Buffer;
};

I have vague memories of being unable to compile a scene component (which my class inherits from) with a default compiler, but in 4.7 and 4.9 the headers clearly show that’s fine. Thanks for the response!

I switched my class over to using a default constructor. However once I reverted CircularBuffer.h to remove the default constructor I added, the problem returned. My class is inherits from USceneComponent. Here’s what’s happening:

Build.h contains

#define WITH_HOT_RELOAD_CTORS 1

In [ProjectName].generated.cpp, there is a line:

DEFINE_VTABLE_PTR_HELPER_CTOR(UVerletVelocityTrackerCmp);

ObjectBase.h defines that macro as follows when WITH_HOT_RELOAD_CTORS is nonzero:

#define DEFINE_VTABLE_PTR_HELPER_CTOR(TClass) \
	TClass::TClass(FVTableHelper& Helper) : Super(Helper) {};

Unreal is generating a constructor for my class for hot reload which relies on default constructors for all of the fields. This is the detail I wasn’t remembering from before. I understand if the nature of the build tool makes this specific thing I’m trying to do impossible, but I wanted to bring it up in case it sounded like a bug.

Thanks.

You are right. This looks like a bug to me. I need to discuss this with the Core team tomorrow.

You can specify your own hot reload constructor. The following works (tested in Master, but should work in 4.9 as well):

#pragma once

#include "CircularBufferObject.generated.h"


UCLASS()
class UCircularBufferObject
	: public UObject
{
	GENERATED_BODY()

public:

	UCircularBufferObject()
		: CircularBuffer(1024)
	{ }

	UCircularBufferObject(FVTableHelper& Helper)
		: Super(Helper)
		, CircularBuffer(1024)
	{ }

private:

	TCircularBuffer<int32> CircularBuffer;
};

This definitely works. Thanks for your help.