Interface methods with {} or = 0. What's the different? Can I use both?

Hi!

I have this interface:

#pragma once


#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "EventManagerInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UEventManagerInterface : public UInterface
{
   GENERATED_BODY()
};

/**
*
*/
class MYGAME_API IEventManagerInterface
{
   GENERATED_BODY()

// Add interface functions to this class. This is the class that will be inherited to implement this interface.

public:

   virtual void AMethod() {};

};

What is the different between this method virtual void AMethod() {}; and this one virtual void AMethod() = 0;?

Someone has said me that the second one is an abstract/pure virtual, you can’t have that in UE reflected classes. All reflected types must be instantiable.

But I don’t know if a reflected class.

Hi! That’s exactly right. A reflected type is generally something that inherits directly or indirectly from UObject, things such as: AActor, UGameInstance, UDataAsset, etc. Those classes cannot contains abstract methods since UE’s object system must be able to instantiate them.

However, C++ interfaces such as your IEventManagerInterface are technically not reflected and may include pure virtual functions. In general, you’d use a pure virtual function when you don’t want to provide a default implementation for that function, requiring derived classes to implement it.

So, if you expect classes using your interface to always provide their own implementation of AMethod(), you may declare it as pure virtual (= 0;). Otherwise, if you’d rather make it optional, leave it just like that, with an empty {}body or some other default implementation.