I mean some thing like this
Code: Select all
class MyObj : public wxObject
{
public:
int x;
Data* myData;
}
Code: Select all
void MyFrame::MyFrameFunc(){
MyObj* obj = new MyObj();
obj->myData = new Data;
}
Any help will be appreciated.
Code: Select all
class MyObj : public wxObject
{
public:
int x;
Data* myData;
}
Code: Select all
void MyFrame::MyFrameFunc(){
MyObj* obj = new MyObj();
obj->myData = new Data;
}
Code: Select all
MyObj* obj = new MyObj();
Code: Select all
class myFrame : public wxFrame {
...
MyObj obj;
...
}
Please take a look at the folowing sequence, which explained the concept of how reference-counting works:Qasim wrote: now will this be referenc counted in Myframe and will be deleted automatically when frame is destroyed ??? or I have got a completely wrong concept of it ?
Code: Select all
MyObj* obj = new MyObj(); //Now the reference count is 1
MyObj* obj_ref1 = obj; //Now the reference count is 2
//If you quit without deleting them now, the reference count is still above 0, so it won't be deleted by wxObject at all.
delete obj_ref1; //Now the reference count is reduced to 1, still above 0, so the real object(not the pointer) won't be deleted.
func(obj); //You can still use obj
delete obj; //Now the reference count is reduced to 0, the real object will be deleted from the heap