Can we have c++ template method in my actors

Can we have class template method like this? Compile failed with a lot of errors that seems to come from macros mess.

UCLASS()
class ULKRUNTIMEMODULE_API AUlkRuntimeActor : public AActor
{
	GENERATED_BODY()

public:
	template <typename T> T* ResolveVariable<T>(const std::string& Name) const; {}
};

Hey @chepiok_pro. It is perfectly acceptable to use template methods for classes in Unreal. Although instead of using std::string, you should use Unreal’s version for a string, like FString, or FName. An example of a template method could look like this:

template <typename T>
T* MyTemplateMethod(const FString& InString) const
{
    // My code here
}

Hope this helps

1 Like

It may not be a popular opinion, but I would not resign from std::string completely, because it has some advantages over FString:

  • small buffer optimization
  • ability to choose an allocator