A myOb; // here the myObj will "live" only in this function
list.append(&myOb);
} //here that object is deleted
// here you don't have it any more
// the myObj scope is in that function,
// and you will try to access it later with the pointer from the list (but the object is gone)
public: void Add(QString s){
A myOb; // here the myObj will "live" only in this function
list.append(&myOb);
} //here that object is deleted
// here you don't have it any more
// the myObj scope is in that function,
// and you will try to access it later with the pointer from the list (but the object is gone)
To copy to clipboard, switch view to plain text mode
A *myOb=new A(); //here you allocate memory on the heap, this will "live" until delete is called
list.append(myOb);
}
// the object is still valid after the execution of the function
// only the pointer "life" is ended, but you have the pointer from the list that will take care of the actual object
public: void Add(QString s){
A *myOb=new A(); //here you allocate memory on the heap, this will "live" until delete is called
list.append(myOb);
}
// the object is still valid after the execution of the function
// only the pointer "life" is ended, but you have the pointer from the list that will take care of the actual object
To copy to clipboard, switch view to plain text mode
References are not pointers. DO NOT code like they can be changed, they are two different types of indirect access to an object
Bookmarks