How to create a C + + singleton for calculation and judgment only

I want to create a C + + singleton to support operations,But when I create a singleton class in C + +, I can’t compile it.
code and compilation errors ↓

class  GENERALCODELIBRARY_API  GeneralAssistCalculateLibrary
{
private:
	static GeneralAssistCalculateLibrary* Instance;
	static void Destructor(){Instance ? delete Instance : nullptr;}
	GeneralAssistCalculateLibrary();
	~GeneralAssistCalculateLibrary();
public:
  static GeneralAssistCalculateLibrary* GetInstance()
   {
   	   return Instance;
   }
#pragma region Network
public:
	
	FORCEINLINE bool ShoudDealDamageByActorNetRole(const AActor* TargetActor)
	{
		return IsValid(TargetActor) && (TargetActor->GetNetMode() != NM_Client)
		||
		(TargetActor->GetLocalRole() & ROLE_Authority)
		|| TargetActor->GetTearOff();
	}
	
#pragma endregion

};
GeneralAssistCalculateLibrary* GeneralAssistCalculateLibrary::Instance = nullptr;

Compilation error:

GeneralAssistCalculateLibrary. H (39): [c4273] “instance”: inconsistent DLL links

GeneralAssistCalculateLibrary. H (39): [c2491] “generalassistcalculatelibrary:: instance”: the definition of dllimport static data member is not allowed

In fact, I think we should use the TSharedptr o manage this singleton, but I have tried many times and there are many compilation errors XD.

If it’s just static utility functions, why instantiate it at all? Just make the functions static. TSharedPtr isn’t going to make any difference here.

Also, you shouldn’t implement static objects in the header. You can’t define them more than once and if you include that header in more than one file you’ll get conflicting defintions. They need to be in a cpp file.

Or better yet, use a Blueprint Function Library

Or if you must define a singleton in the header for some reason (such as for a class that has no implementation file), do so within the function that returns the singleton. For instance:

class Foo {

public:

    static Foo* Instance() {
        static Foo FooInstance();
        return &FooInstance;
    }

}

That said, singletons are not always the right design pattern to use, and I kind of suspect that’s the case here.

If it’s just a collection of utility functions with no actual object state that requires instantiation, then as TheJamsh says, it’d probably make more sense to implement as a Blueprint Function Library. Not only will that serve the purpose you seem to be aiming for here (and avoid the need to allocate – and eventually, free – an instance of the class if you have a class that you actually have to allocate as a pointer), but you’ll also be able to use those static utility functions as nodes in a Blueprint if needed!