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
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.
There is no problem with the definition. There are problems with getting arrays of different dimensions as a function parameter.
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...
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.
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...
And what does this have to do with your task (class of tasks - unified work with arrays of different dimension via functions)?
Try to define a class so that a function call to an array of different dimensions looks the same.
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?
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.
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?