delete object copy

To add comments, please log in or register
Christian Stern
322
Christian Stern  

Hey all,


i have a understanding question. When i create a struct which has a object and a loaded indicator in it, like this:

// define struct
struct foobar {
        MyClass obj;
        int     maHandleID;
}

// create variable
foobar foo;

// assign object
MyClass *foo.obj = new MyClass();

// assign indicator
foo.maHandleID = iMA(Symbol(),Period(),8,0,MODE_SMA,PRICE_CLOSE);


Now i create a copy of if:

// define tmp struct
foobar foo2;

// copy struct
foo2 = foo;


After finish work, i cleanup structure "foo" and lets say, reassign structure "foo2" to "foo".

During the cleanup i delete the object with:

// delete orginal
delete(foo.obj);

// Zero value
ZeroMemory(foo);

// restore from copy
foo = foo2;

// etc ....


When i delete the object in the structure whats happened with the object and object data of the copy ? Like when inside of the object a indicator is with id xy, which exists hat this moment twice. If in the destructor is a routine to release the indicator, then the indicator pointer of the copy becomes invalid.

Does someone can explane me that ?


Thank you in advanvced

whroeder1
17927
whroeder1  

Your class/struct has no destructor, therefor nothing "happened with the object and object data of the copy." You had two copies of the indicator's handle. then you have one.

If you release the indicator, then yes "the indicator handle of the copy becomes invalid." (MQLx has no pointers only a descriptor.)

Explain what? You haven't asked a question.

Christian Stern
322
Christian Stern  
whroeder1:

Your class/struct has no destructor, therefor nothing "happened with the object and object data of the copy." You had two copies of the indicator's handle. then you have one.

If you release the indicator, then yes "the indicator handle of the copy becomes invalid." (MQLx has no pointers only a descriptor.)

Explain what? You haven't asked a question.


Thank you for your answer. I solved it, it was too late and i was coding too long ..just saw only if's and while's.

Next day i did a review of the code and saw my fauxpas, i used the delete() at the wrong place, so the descriptor becomes invalid.


It's a bit irritating -> "MQLx has no pointers" but the function calls "GetPointer()" and "CheckPointer()". ;)

To add comments, please log in or register