So, i have this class which i set as attribute a pointer of an object from another class. Something like:
1 2 3 4 5 6
class Test
{
public:
RobGeek *obj;
//...other attributes and code here.
};
1 2 3 4 5 6 7 8 9 10 11 12
Test( )
{
//code here in the constructor
obj = new RobGeek;
if(//i check if an attribute of "obj" is setted properly)
{//code here}
else
{
obj = NULL;
//or
delete obj;
//try other constructor of RobGeek
That is the idea. I try to create this object and check if he is ok, if not i try the other way, but i don't know the difference between "delete obj;" and "obj = NULL;"
Keep this as a rule of thumb. For every new there should be one delete. So you very much want to delete that.
Recently in a video i encountered, the person in question said that it is good programming practice to also do obj = nullptr; // note: nullptr not NULL after deleting. Ive read some stuff and its more like "it doesnt hurt". You can read move about it somewhere here, pick your poison.