Frika:
Hello,
I have an array with struct members. The struct is also including strings.
In the end, is it possible now to remove arr[3]?
Thank you
If you don't care about the order:
Copy the last index to [3]
Resize the array to be 1 less.
int cnt = ArraySize(arr)-1; int remove = 3; arr[remove].a = arr[cnt].a; arr[remove].b = arr[cnt].b; ArrayResize(arr,cnt);
(uncompiled)
Create a copy constructor and just move higher elements down, like any other data type. | #define INDEX uint template<typename Ti, typename To> INDEX copy(const Ti& inp[], INDEX iBeg, INDEX iEnd, To& out[], INDEX oBeg=0){ while(iBeg != iEnd) out[oBeg++] = inp[iBeg++]; return oBeg; } template<typename T> void remove_at(T& vector[], ///<[in,out] The vector. INDEX index) /**<[in]Location. */{ INDEX iEnd = ArraySize(vector); if(index != iEnd) iEnd = copy(vector, index+1, iEnd, vector, index); } struct test{string a; int b; void operator=(const test& that){ this.a=that.a; this.b=that.b; } }; // remove arr[3] remove_at(arr, 3); |
Thank you both, very smart and very professionel.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I have an array with struct members. The struct is also including strings.
In the end, is it possible now to remove arr[3]?
Thank you