Download

note: see reference to class template instantiation 'TArray' being compiled

Hi all,
trying to create a function in my .cpp like this:


 void ASomeActor::SomeFunction(TArray<Room> roomList_)   <--- this is the line giving the error
 {
       //...
 }


defined in the .h like this:


 void SomeFunction(TArray<Room>& roomList_);


in the constructor I have:


 TArray<Room> roomList_;


and finally the function is called always inside the constructor like this:


 SomeFunction(roomList_);


Can’t figure out the proper syntax to pass TArrays as arguments…
Hope someone can help.
Thanks in advance.
Bye

Surely that is not the entire error? Would be helpful the see all of them.

For now I can spot that in your header the function argument roomList_ is a reference to TArray<Room> while it no longer is a reference type in the cpp file.


 void ASomeActor::SomeFunction(TArray<Room>**&** roomList_) // or leave this unchanged and remove the & in the header file
 {
       //...
 }

Another thing I can only speculate about is that Room is either an Actor class (a UObject) or a struct and should therefore be prefix with either A, U or F (depends on your “Room”).

Hi UnrealEverything,
that is the whole error I’m afraid…
You are right about the ampersand, it slipped in there in one of the various attempts to make the code work.
Room is a c++ native struct.

EDIT: worth to mention that IntelliSense doesn’t highlight anything, the error is when trying to compile from UE
EDIT2: I think you are onto something there with prefixes, could you elaborate it a bit please?
EDIT3: correct syntax provided in the AnswerHUB

Anything that inherits from Actor should be prefixed with ‘A’, which the class wizard will do automatically when you give the files a name. Anything that inherits from UObject should be prefixed with ‘U’. Structs should be ‘F’. Enums should be ‘E’ etc. I believe this is actually necessary for the build tool to work properly.

Room is actually based on an Actor or a UObject class right? Otherwise TArray won’t work with it. Show us your ‘Room’ .h file (the whole thing)

AFAICT, it looks like the Compiler has no idea what ‘Room’ is.

EDIT: Also, you should use the ampersand when passing arrays, otherwise you copy the entire thing and that is not only slow, but can quickly lead to fragmented memory.

Hi TheJamsh,

I’d like to know why you mentioned fragmented memory. Are you referring that Unreal’s memory management cause fragmentation?

Thanks!

Well depending on the size of the array, it may not lead to that since the copy would be created on the stack and then removed later. You could get a stack overflow though, if the array is large enough.

However you’d still have to copy that block of memory from the heap to the stack first I think, so accessing the array “in place” is often better and faster.

Ok I get it, I think I misunderstood your post.
The local variable array is created by C++'s mechanism, not allocated by Unreal, of course.