@RoboPogo : "any time a reference to an object is made, a function is called" That seems to me a really weird practice. What is a use case for this ?
Object obj;
Object *obj1,*obj2;
obj1 = &obj; // to be intercepted
obj2 = obj1; // to be intercepted
@Stanislav Korotky : "All you can do, if you want to intercept operations with a pointer, is to create another class, say SafePointer, which will control access to a contained pointer." So that means each time "a reference to an object is mode", you will have to do a duplicate statement to SafePointer object ? I am understanding well ?
@nicholishen : I can't see how your code is answering to the OP requirement ? There is no reference to an existing object in your code, a,b,c,d are 4 different objects. If you made "a reference to an object", nothing is intercepted.
Object a(10),b;
b=a;
Object *c = new Object();
c=b;
Object *d = c.AssignNew();
Object obj = d;
Print("Object obj.val = ",obj.val);
//this
a=d;
//is the same as this
a.Assign(d);
@RoboPogo : "any time a reference to an object is made, a function is called" That seems to me a really weird practice. What is a use case for this ?
@Stanislav Korotky : "All you can do, if you want to intercept operations with a pointer, is to create another class, say SafePointer, which will control access to a contained pointer." So that means each time "a reference to an object is mode", you will have to do a duplicate statement to SafePointer object ? I am understanding well ?
@nicholishen : I can't see how your code is answering to the OP requirement ? There is no reference to an existing object in your code, a,b,c,d are 4 different objects. If you made "a reference to an object", nothing is intercepted.
If I am missing something, please enlighten me.
I don't have time to go through the entire thread, however, the OP was attempting to call his overloaded operator (a class method) on a null-pointer. Null-pointers, as you very well know, are incapable of performing any logic because they are, well, null. My code was to show OP alternatives to his conceived pattern.
I don't have time to go through the entire thread, however, the OP was attempting to call his overloaded operator (a class method) on a null-pointer. Null-pointers, as you very well know, are incapable of performing any logic because they are, well, null. My code was to show OP alternatives to his conceived pattern.
No problem. Ok about the null-pointer issue, however, he was doing that while trying to "call a function any time a reference to an object is made", so when you have time and interest, it would be nice to confirm your code doesn't answer this question. Or to show how it answers it.
No problem. Ok about the null-pointer issue, however, he was doing that while trying to "call a function any time a reference to an object is made", so when you have time and interest, it would be nice to confirm your code doesn't answer this question. Or to show how it answers it.
There is no answer to OP - because OP didn't understand how pointers worked. There are only alternative options, which I attempted to share.
Sorry if its not directly related to the post, but not long ago I recall seeing a new mql5 version with built in copy constructor called when assigning one object to another. Anyone can point me to this doc?
Ok, here it is at point 8. It is pitty that all changes are not consentrated in one place.
MQL5: Added automatic generation of an implicit copy operator for
the objects of structures and classes. Now, the compiler automatically
creates copy operators, which allows writing simple entries for objects,
such as b=a:
Memberwise copying of objects is performed in the implicit operator.
If a member is an object, the corresponding copying operator for this object is called.
If a member is an array of objects, the receiving array is
increased or reduced to the require size using ArrayResize before
calling the appropriate copying operator for each element.
If a member is an array of simple types, the ArrayCopy function is used for copying.
If a member is a pointer to an object, the pointer is copied rather than the object to which it points.
If necessary, you can override the behavior and create your own option instead of an implicit copy operator, using overloading.
Amir Yacoby: Sorry if its not directly related to the post, but not long ago I recall seeing a new mql5 version with built in copy constructor called when assigning one object to another. Anyone can point me to this doc?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
This topic is really confusing at levels.
@RoboPogo : "any time a reference to an object is made, a function is called" That seems to me a really weird practice. What is a use case for this ?
@Stanislav Korotky : "All you can do, if you want to intercept operations with a pointer, is to create another class, say SafePointer, which will control access to a contained pointer." So that means each time "a reference to an object is mode", you will have to do a duplicate statement to SafePointer object ? I am understanding well ?
@nicholishen : I can't see how your code is answering to the OP requirement ? There is no reference to an existing object in your code, a,b,c,d are 4 different objects. If you made "a reference to an object", nothing is intercepted.
If I am missing something, please enlighten me.
This topic is really confusing at levels.
@RoboPogo : "any time a reference to an object is made, a function is called" That seems to me a really weird practice. What is a use case for this ?
@Stanislav Korotky : "All you can do, if you want to intercept operations with a pointer, is to create another class, say SafePointer, which will control access to a contained pointer." So that means each time "a reference to an object is mode", you will have to do a duplicate statement to SafePointer object ? I am understanding well ?
@nicholishen : I can't see how your code is answering to the OP requirement ? There is no reference to an existing object in your code, a,b,c,d are 4 different objects. If you made "a reference to an object", nothing is intercepted.
If I am missing something, please enlighten me.
I don't have time to go through the entire thread, however, the OP was attempting to call his overloaded operator (a class method) on a null-pointer. Null-pointers, as you very well know, are incapable of performing any logic because they are, well, null. My code was to show OP alternatives to his conceived pattern.
I don't have time to go through the entire thread, however, the OP was attempting to call his overloaded operator (a class method) on a null-pointer. Null-pointers, as you very well know, are incapable of performing any logic because they are, well, null. My code was to show OP alternatives to his conceived pattern.
No problem. Ok about the null-pointer issue, however, he was doing that while trying to "call a function any time a reference to an object is made", so when you have time and interest, it would be nice to confirm your code doesn't answer this question. Or to show how it answers it.
No problem. Ok about the null-pointer issue, however, he was doing that while trying to "call a function any time a reference to an object is made", so when you have time and interest, it would be nice to confirm your code doesn't answer this question. Or to show how it answers it.
There is no answer to OP - because OP didn't understand how pointers worked. There are only alternative options, which I attempted to share.
Copy constructors are fairly straightforward, you can simply create an overloaded constructor that takes in the same class as an argument.
You can step through this example to see what's happening.
Ok, here it is at point 8. It is pitty that all changes are not consentrated in one place.
MQL5: Added automatic generation of an implicit copy operator for the objects of structures and classes. Now, the compiler automatically creates copy operators, which allows writing simple entries for objects, such as b=a:
Memberwise copying of objects is performed in the implicit operator.
If necessary, you can override the behavior and create your own option instead of an implicit copy operator, using overloading.
Sorry if its not directly related to the post, but not long ago I recall seeing a new mql5 version with built in copy constructor called when assigning one object to another. Anyone can point me to this doc?
Copy constructors are fairly straightforward, you can simply create an overloaded constructor that takes in the same class as an argument.
You can step through this example to see what's happening.
Seems completely off-topic.
This is the relation, its not direct relation I agree.