How to correctly parse a value from class a to class b using getter function

Hello, after some time of struggling with this, I decided to ask here for help. What I need to do is to parse a value declared in in TestClassB.h to TestClassA.cpp using a getter function.

This is what I am stuck with on:

//TestClassB.h
class UTestClassA
{
private:
    static int TestValue;
public:
    static int GetTestValue();
};
    
//TestClassB
int UTestClassA::GetTestValue()
{
    return TestValue;
}

Upon compilation its giving me an error: unresolved external symbol “private: static int UTestClassA::TestValue” (?TestValue@UTestClassA@@0HA)

Hello.

In case of static properties, you have to additionally define them just as you do with functions.
Adding following line in your cpp file should solve the issue.

int UTestClassA::TestValue = YOUR_VALUE;

Additionally, in UE4 you shouldn’t use int type. Instead of this go for one of engine typedefs: uint8, int8, uint16, int16, uint32, int32 etc.

Cheers.