-
CSnrRange* copy = CSnrRange(firstRange); // 2021.04.26 12:47:38.679 Test GBPUSD,Daily: invalid pointer access in 'Test.mq4' (56,15)
You call the copy constructor the result is an unnamed object. You then try to assign the object to a pointer.
-
CSnrRange::CSnrRange(const CSnrRange &range) { EarliestTime = range.EarliestTime; HighTime = range.HighTime; HighVal = range.HighVal; LowTime = range.LowTime; LowVal = range.LowVal; Ignore = range.Ignore; }
I almost always name the right hand side that, and construct the object, not assign to it after construction:CSnrRange::CSnrRange(const CSnrRange &that) : EarliestTime(that.EarliestTime), HighTime(that.HighTime), HighVal(that.HighVal), LowTime(that.LowTime), LowVal(that.LowVal), Ignore(that.Ignore) {}
Just copy the object.
CSnrRange copy(firstRange);
William Roeder:
-
You call the copy constructor the result is an unnamed object. You then try to assign the object to a pointer.
- I almost always name the right hand side that, and construct the object, not assign to it after construction:
Just copy the object.
Thank you very much for pointing this out! I appreciate it :)
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
Hi there,
Some very simple code below to illustrate a problem I'm having. I have a very simple class with a copy constructor. The sample below creates a new object and then tries to make a copy of that object via the copy constructor whereupon I get the invalid pointer access error/message.
What am I doing wrong here?
Many thanks.