MQL5 The compiler does not distinguish between a class and a pointer to it - page 2

 
SemenTalonov:

That's what I was expecting the copy... The default copy constructor is not an error.

ButDmitry says a new object will be allocated in memory and a pointer ofPOINTER_AUTOMATIC type will be returned.

Everyone understands MQL quirks in his own way)

Yep. It turns out there is no Father Christmas.

I haven't written about any object in memory.

OK, there were disputes once about how to distinguish a reference from a pointer. But now it seems we cannot distinguish an object from a pointer.

 
Dmitry Fedoseev:

Where does a copy of an object come from? A copy of a pointer, yes, but pointing to the same object.

We have an array of objects. An assignment operator is called on the first element of this array, which is passed the separately created object (although, the operator is undeclared). What do you think should be in the first element of the array after that? In my opinion, the object should remain.

 
SemenTalonov:

My point is that an explicitly declared copy constructor would not change anything in this test.

How can you fail to see the obvious...

An object array item contains a pointer and an object in the pointer array item... is this really normal?

In the first case, an object pointer goes to the array in the second case, the copy constructor should work, how can these operations be equivalent?

Not the copy constructor, but the assignment operator, but that's the little things.

It's the object that should go into an element of an object array.

In the first case - you have exactly an object array, what kind of "pointers"?

 
Georgiy Merts:

We have an array of objects. The assignment operator is called at the first element of this array and the separately created object is passed to it. What do you think should be in the first item of this array after that? In my opinion, the object should remain.

А... It's not good there at all))) An array of automatic pointers, and in it they also cram an object created dynamically. Then there are 3 objects, two of them will be automatically deleted and one will leak. If it is compiled.

 

It should be like this:

A* m_A[2];

and so:

m_A[0] =GetPointer(a); 
 

And at the end it goes like this:

for(int i=0;i<2;i++)if(CheckPointer(m_A[i])==POINTER_DINAMIC)delete(m_A[i]); 
 
Dmitry Fedoseev:

А... It's not good there at all))) An array of automatic pointers, and they also cram in an object created dynamically.

Finally!))

Georgiy Merts:

It's the object that must be placed in the object array element.

In the first case - you have exactly an array of objects, what "pointers"?

That's my point ! Why does it WORK?!

m_A[1] = new A();
 
SemenTalonov:

Finally!))

That's my point! Why does it WORK?!

If A is declared so:

A* m_A[2]; 

Then it's OK.

And if it's like this:

A m_A[2]; 

It shouldn't compile. Either there is a bug in the compiler, or the compiler doesn't have to think for everyone.

 
It's probably not a bug, but assigning simple objects should work, so you have to take care of deleting the object you created with new.
 
Dmitry Fedoseev:

Then it shouldn't compile. Either there's a bug in the compiler, or the compiler doesn't have to think for everyone.

Bingo!

SemenTalonov2019.01.10 07:36POINTER_AUTOMATIC type to a pointer of thePOINTER_DYNAMIC typeand vice versa.