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
Interesting:
The method proposed by Alexander(AlexSTAL) might have solved the problem (let's not take into account its certain problematic nature).
Whoa, whoa, whoa, whoa!
I did not suggest it, I said that there is a possibility.
And what's your problem, I can't understand?
You must be discussing an example where half of the logic is missing and half is wrong (left over from the inception of OOP)?
Whoa, whoa, whoa, whoa!
I didn't suggest it, I said there is a possibility.
And what's your problem, I can't understand?
Let's say you need to put different objects in an array.
At the same time, all properties of these objects should be stored in the same array + there should be access to all events and methods.
The possibility offered by you (the implementation may be different) as far as I understand, allows access to the objects functionality (events and methods).
But the storage of data in an array with an ancestor type is unlikely to work (given that this data was not declared in the ancestor).
Let me clarify my thought.
If we stop at this particular example, then:
1. Say, we can create an array which will store the type of object, position in X, position in Y;
2. We could try to identify a unique object by its pointer (although when working with an object, the pointer might not be used, then it would be desirable to have something like a handle);
A silly question (I see no other solution), why use a pointer as a handle (create a property in the ancestor and fill it in the constructor)?
We don't get the ability to store descendant properties in an array (only those which aren't defined in the ancestor). For example, as far as I understand, we cannot store the radius of a circle or the side of a square in an array.
3. we don't get the ability to store descendant properties in the array (only those not minted in the ancestor). For example, as far as I understand, we can't store the radius of a circle or the side of a square in an array.
Why wouldn't it work... You don't address them directly, but use your "GetValue" function with the "radius" parameter (if the object is a circle)... This is as one possibility...
You set a simple specific task
Why wouldn't it work... You don't address them directly, but use your "GetValue" function with the "radius" parameter (if the object is a circle)... This is as one possibility...
You set a simple, specific problem
The task is simple, but who's to say it's easy to implement.
The task is to record into an array various objects (descendants of the base class) along with their data.
Let's make it clear, that together with their data!!!
2. GetArea() for each descendant;
3. Add the following features:
a. Calculate the perimeter of the square - side *4;
б. Calculation of perimeter of a circle - 2πR.
3. Add additional shapes to the library - rectangle (two sides) and triangle.
4. Add the following features:
a. calculate the area of a rectangle - base by height;
б. Calculate the perimeter of a rectangle - sum of sides *2;
в. Calculation of the area of a triangle;
г. Calculation of the perimeter of a triangle.
5. Identify each object individually (among all objects and among objects of its class).
Preferably with or without pointers.
6. Calculate the perimeter and area of the shapes using only the data stored in the array.
PS
It is not allowed to transfer code from descendants to the ancestor (unless this code applies to all ancestors).
I.e. you cannot, for example, transfer a radius into an ancestor, since a square, a rectangle and a circle do not have one.
New functionality can be added to an ancestor as long as it applies to all the descendants.
We take the code in the trailer as a basis.
Within a single array, I personally solved the problem simply by adding variables for storing area and perimeter to the ancestor + functionality to write data to them.
In this case, if the result of GetArea() and other functions of direct calculation is controlled.
I don't seem to have broken my own rules.
I have sketched one way of implementing the approach you describe.
It is not complete, but it is the most important approach
I have sketched one way of implementing with the approach you describe.
It is not complete, but it is the most important approach
The approach is clear. It is probably one of the best solutions to a similar problem.
At least for now.
The task is simple, but who says it's easy to implement?
1. the task is to write different objects (descendants of a base class) together with their data to an array.
...Spreadsheets in MQL5 have already solved and described the problem.
How good it is to be able to read... :)
Also not bad approach, though as I understood both these approaches are calculated on transfer/reading of only one parameter (albeit of different types).
But what to do if there are a lot of parameters and it's impossible to fit them all into a base class?
As far as I understand, the index of the parameter to be passed should be entered additionally (also, an array with parameters stacked by index can be created in the class).
How good it is to be able to read... :)
Also not bad approach, though as I understood both these approaches are calculated on transfer/reading of only one parameter (albeit of different types).
And what to do if there are a lot of parameters and it is impossible to include them all into base class?
As far as I understand, it is possible to enter an index of the parameter to be passed (also it is possible to create an array with parameters stacked by index in a class)?