many thanks to formed code. :-)
please suggest where wrong coding rules in this code.
...why foo2 initialize passed by operator=() ?
Because you are using a copy, not ? Try this :
printf("foo2 create."); foo foo2(foo1); //instantiate by copy constructor
why foo3 initialize passed by copy constructor?
thanks.
Because "this" creates a copy.
foo* operator=(const foo &sourceFoo) { printf("foo operator= source = [%s], destination = [%s]",sourceFoo.s,s); s=sourceFoo.s; return(GetPointer(this)); }
Because you are using a copy, not ? Try this :
Because "this" creates a copy.
It is the purest initialization here, NOT an assignment:
printf("foo2 create."); foo foo2 = foo1; //instantiate by copy constructor
Aren't you confused with the "(null)" value of s in the next line of the log?
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo operator= source = [foo1], destination = [(null)]
The operator =() is called for an object that is NOT still constructed, and the next log line gives us a confirmation that the copy constructor for the object is called then, i.e. AFTER the operator =():
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo copy constructor source = [foo1]
Obviously, and absolutely no doubts that this is the bug of one of the latest versions, because the code for the version 625 produces the log WITHOUT the wrong operator =() call:
2014.05.08 01:38:05.891 1 USDCHF,H1: foo copy constructor source = [foo1]
2014.05.08 01:38:05.891 1 USDCHF,H1: foo operator= source = [foo1], destination = [foo3]
2014.05.08 01:38:05.891 1 USDCHF,H1: foo constructor [foo3]
2014.05.08 01:38:05.891 1 USDCHF,H1: foo3 create.
2014.05.08 01:38:05.891 1 USDCHF,H1: foo copy constructor source = [foo1]
2014.05.08 01:38:05.891 1 USDCHF,H1: foo2 create.
2014.05.08 01:38:05.891 1 USDCHF,H1: foo constructor [foo1]
2014.05.08 01:38:05.891 1 USDCHF,H1: foo1 create.
2014.05.08 01:38:05.891 1 USDCHF,H1: initialized
As you can see, for the version 625 there is no operator =() call before the copy constructor call.
And "this" does NOT create a copy. Returning non-reference type from the operator =() creates a copy. But MQL4 compiler effectively resists use of references in return values in poor English: "'&' - reference cannot used". No doubts that MQL4 type scheme is designed defectively. For example, in C++ operator =() returns reference.
That's the truth.
sorry to delayed response.
angevoyageur:
very thanks to escorting thread. I've been very helpful.
I will report service desk for this issue.
simpleton:
I'm glad to teaching for me.
difficulty learn to MQL5 OOP class behavior...
sorry to delayed response.
this issue was fixed at Build 945 on later.
many thanks to helps and advise. :-)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
please suggest where wrong coding rules in this code.
when I written below class.
foo2, foo3 called unexpected copy constructor and operator=() each objects.
execution result paste in below.
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo copy constructor source = [foo1]
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo operator= source = [foo1], destination = [foo3]
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo constructor [foo3]
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo3 create.
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo copy constructor source = [foo1]
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo operator= source = [foo1], destination = [(null)]
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo2 create.
2014.05.07 02:25:28.476 OOPtest (AUDCAD,H1) foo constructor [foo1]
2014.05.07 02:25:27.421 OOPtest (AUDCAD,H1) foo1 create.
why foo2 initialize passed by operator=() ?
why foo3 initialize passed by copy constructor?
thanks.