# Best way to use a static function library in c++? Instancing etc...

**URL:** <https://forums.unrealengine.com/t/best-way-to-use-a-static-function-library-in-c-instancing-etc/51583>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [January 5, 2016, 7:01pm UTC](https://forums.unrealengine.com/t/best-way-to-use-a-static-function-library-in-c-instancing-etc/51583 "2016-01-05T19:01:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanaFo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DanaFo](https://forums.unrealengine.com/u/DanaFo)\
**Post date:** [January 5, 2016, 7:01pm UTC](https://forums.unrealengine.com/t/best-way-to-use-a-static-function-library-in-c-instancing-etc/51583/1 "2016-01-05T19:01:08Z")

</div>

Hi,  
I am building up a static function library for use both in BP and c++, and I was wanting to use one of the static lib member funcs in my c++ pawn class.

Now I know I need to create an instance of the static lib object in order to invoke it’s member funcs… but I was curious if it was more \*efficient \*to create the instance in the ‘begin play’ of the pawn or to create the instance in the pawn’s member function where I specifically want to use the static lib func.

Thanks again!

(I can post code but doesn’t seem necessary…?)

---

<div class="post-metadata">

**Author:** ![UnrealEverything](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnrealEverything](https://forums.unrealengine.com/u/UnrealEverything)\
**Post date:** [January 5, 2016, 8:28pm UTC](https://forums.unrealengine.com/t/best-way-to-use-a-static-function-library-in-c-instancing-etc/51583/2 "2016-01-05T20:28:15Z")

</div>

You don’t need to create an instance of the static lib object to be able to use its static member functions. This works:

BPFuncLib.h

```auto

//includes etc.

UCLASS()
class PROJECT_API UBPFuncLib : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	virtual ~UBPFuncLib();

	UFUNCTION(BlueprintCallable, Category = "Your Category", Other Function Specifiers)
	static FYourReturnType Function(FYourFunctionParameters Parameters);
	
};

```

```auto

#include "BPFuncLib.h"

UBPFuncLib::Function(Parameters);

```

In case I’m understanding your question/problem correctly, you don’t have to worry about efficiency.

---

<div class="post-metadata">

**Author:** ![DanaFo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DanaFo](https://forums.unrealengine.com/u/DanaFo)\
**Post date:** [January 5, 2016, 8:48pm UTC](https://forums.unrealengine.com/t/best-way-to-use-a-static-function-library-in-c-instancing-etc/51583/3 "2016-01-05T20:48:53Z")

</div>

Ah interesting. See I was using Rama’s example:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

and I realized that setting the (edit: didn’t mean to use the word virtual here) member functions to static allowed me to then do what you said (I was tripping a break trying to create an instance of the static lib class so I had to do some digging).

Would you be so kind as to explain as to why making it a virtual is useful and what does the ‘~’ do in that case as a prefix?

Thank you again!

---

<div class="post-metadata">

**Author:** ![UnrealEverything](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnrealEverything](https://forums.unrealengine.com/u/UnrealEverything)\
**Post date:** [January 6, 2016, 10:26am UTC](https://forums.unrealengine.com/t/best-way-to-use-a-static-function-library-in-c-instancing-etc/51583/4 "2016-01-06T10:26:35Z")

</div>

> [@DanaFo;448212](#):
>
> Would you be so kind as to explain as to why making it a virtual is useful and what does the ‘~’ do in that case as a prefix?

The ‘~’ character denotes the destructor of the class. I don’t think you actually need it, I usually add it just in case I need it later.  
It’s virtual so that any derived class destructors are called in order when a pointer to a base class is deleted.
