How do I remove an element from an array (one-dimensional two-dimensional)? - page 6

 
Aliaksandr Hryshyn:
Is there a problem with defining dimensionality?

There is no problem with the definition. There are problems with getting arrays of different dimensions as a function parameter.

 
Arrays do not have more than 4 dimensions here. So, you can write 4 different functions and that's it.
 
Ilya Malev:

There is no problem with the definition. There are problems with getting arrays of different dimensions as a function parameter.

Use classes for such things. Pass an instance of a class with different arrays to the function...
 
Dmitry Fedoseev:
Arrays don't have more than 4 dimensions here. So, you can write 4 different functions and that's it.

You may not use arrays of size greater than 1 at all, and if you want to manipulate something with different fields, you can use an array of structures or a list of objects. I personally always do that when I write something myself. But in somebody else's code, which I also encounter, I also come across options like a multidimensional array. And here begins the fun part...

 
Aliaksandr Hryshyn:
Use classes for such things. Pass an instance of a class with different arrays to the function...

Try to define a class so that a function call applies to an array of different dimensions will look the same.

 
Ilya Malev:

Normal questions, you should have ignored the brackets in the title of the thread. Without knowing the number of elements - you can. If you don't know the dimensionality, you can't.

Let me tell you a terrible secret. An array is one-dimensional. Any kind. I already told you...

 
Алексей Тарабанов:

I'll let you in on a terrible secret. The array is one-dimensional. Any kind. I already told you...


Ilya Malev:

And what does this have to do with your task (class of tasks - unified work with arrays of different dimension via functions)?

 
Ilya Malev:

Try to define a class so that a function call to an array of different dimensions looks the same.

I mean, you have to define the required array(s) in a class and pass the function an instance of that class.
 

An interesting phenomenon...

When you write a function for your collection, the question arises: is it better to make it work fast (without checking), or foolproof, so that the reasonableness of parameters can be checked and corrected?

void ArrayDelete(int & a[],int Start,int Count=1){
   ArrayCopy(a,a,Start,Start+Count);
   ArrayResize(a,ArraySize(a)-Count);
}

Or with foolproof protection, so that reasonable parameters can be checked and adjusted? Here you see that the fast version is not worthy of a collection, because it's easy to write and it is not very useful. And variant with all checks is good only as a museum piece, because you don't need unnecessary brakes. And that's why you don't need it at all.

 
Aliaksandr Hryshyn:
I mean that the required array(s) should be defined in a class and an instance of this class should be passed to a function.

If we look at the problem this way, then multidimensional arrays should not be declared at all - arrays of structures with different fields should be used instead. But the question is different - what can we do with existing array of arbitrary (unknown in advance) dimensions?

Reason: