Help for understand some concepts with UObject

Hello. I noob with C++, i trying to understand that but i think i missed some concept about programming. I think must be something basic but … noob here.

I have that:

.h

UCLASS(BlueprintType, Blueprintable)
class DESKCAPTURELIB_API UDeskCapture : public UObject
{

	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, Category = "Desk Cap")
	void AddStringToArray(FString Test);
	UFUNCTION(BlueprintCallable, Category = "Desk Cap")
void SetText(FString Test);    

protected:
	TArray<FString> TestString;


};

.cpp

    UDeskCapture::UDeskCapture(const class FObjectInitializer& PCIP)
    	: Super(PCIP)
    {
    
    	
    }
    
   void UDeskCapture::GetText(Fstring Test)
{
	AddStringToArray(Test);
}
    
    void UDeskCapture::AddStringToArray(FString Test)
    {
    	TestString.Add(Test);
    }

Playing with BP works. The problem i have its if i want to use AddStringToArray from another place in C++ i use that:

UDeskCapture::AddStringToArray(Test);

And give a error.

C2352 UDeskCapture::AddStringToArray invalid call member no static

if i change to static not give me the error on the call, but give a error when where add to array

C2228: left operator .Add must have class/struct/union.

The question its what concept i missed for doing something like this? how i do something like this?

Any help will be appreciate. Thanks

Hey knack-

Where are you trying to use UDeskCapture::AddStringToArray(Test);? If you are still within DeskCapture.cpp you should only need AddStringToArray(Test); since you’re still working within the same class.

If you are trying to call AddStringToArray from another class you first have to use an include statement to include DeskCapture.h in the other class so that it understands what DeskCapture and AddStringToArray are. You will then need to add a pointer reference to UDeskCapture which allows you to use the pointer to access AddStringToArray in the form of RandomVariable->AddStringToArray("Some string");

Static syntax is:

SomeClassType::SomeStaticFunction();

Instance syntax is:

SomeClassType* Item = new SomeClassType;
Item->SomeNonStaticFunction();

Static functions operate on the type as a whole, whereas instance functions are on a per instance basis. With that said, you must be creating an instance in Blueprints and operating on it.

Thanks. I think i need a instance but still not sure how to do what i want. I now i missed a concept for create what i want but not figure what.

I will try working on more complete code for show more explicit my problem or.

But idea simplified i have a function that call other functions in the code (not same class where i have AddString… ) that generate let say when i call it from BP 4 strings, one each, i want be able add “AddStringToArray(thisString)” in each function to send to a another class for store in a array, for access from BP to this array.