Comparing Structs within an array
I was wondering how best to handle an array of structs. Basically, I have a struct that stores information about n item in the inventory, I then store this in an array, but i noticed that the standard array functions dont work as it cant compare two structs. I am assuming I need to create a custom function too compare the properties of the structs and then use tthat when trying too add/remove. i.e. iterate over the array and compare each one before determining if it can be added or not.
I was just wondering if this is the best way?
Also is there a way to make sure each instance of the struct has a uniqueID, i.e. when the struct is established it gets a unique number.
asked Jun 24 '16 at 01:16 PM in C++ Programming
Ok. It seems you have to add const after your Argumentlist.
This worked in my project :)
answered Jun 25 '16 at 12:04 PM
can you provide the criteria which allows the struct to be added into the Array?
If the criteria is that you don't want to put one struct twice into the Array you can simply use the AddUnique Method of TArray.
If the criteria is more complex I would suggest you to write an overloaded operator for your struct which compares them.
If you don't know how to do this:
To give your Struct Unique IDs:
I hope I could help you :) If not, I'm glad to give some more Input ;)
answered Jun 24 '16 at 01:59 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here