x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I correctly use pointers in this situation?

Hello.

I'm desperately trying to remember C++ right now and I have stumbled across this problem.

I'm trying to deserealize data from JSON for which I am using UE4 libraries.

Consider the signature for the FJsonObject::TryGetArrayField method that I am trying to use:

 bool TryGetArrayField
 (
     const FString & FieldName,
     const TArray < TSharedPtr < FJsonValue > > *& OutArray
 )

This code works if I pass a variable declared as const TArray<TSharedPtr<FJsonValue>> *OutArray as the second parameter, but leaves me wondering about 2 things:

1) Isn't there a better way to use pointers in case of "OutArray" variable? Can I avoid using the native const "*" pointer here and use a smart pointer instead? Using TSharedPtr<TArray<TSharedPtr<FJsonValue>>> OutArray gives me compile time errors about assigning temporary object to a reference.

2) Why does trying to delete "OutArray" pointer later on gives me an exception at runtime? Does that mean UE4's GC manages this pointer for me? How can I be aware if data reference by "*" pointer is managed by GC if it's not an explicit "UPROPERTY()"?.

Thanks in advance.

Product Version: UE 4.16
Tags:
more ▼

asked Aug 28 '17 at 12:05 PM in C++ Programming

avatar image

glen-v
1 1 2

avatar image UnrealDev00 Sep 16 '17 at 07:10 PM

I have the exact same question...

OutArray should just be a reference to a pointer that is pointing to a const TArray.

So if I pass in a const TArray<TSharedPtr<FJsonValue>> *myOutArray to FJsonObject::TryGetArrayField, when it returns myOutArray will be pointing to memory somewhere. Who's managing that memory?

Maybe I just suck at C++ and I'm missing something?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question