struct Foo
{
Obj* pObj;
Foo() : pObj(NULL);
};
Obj* CreateObj()
{
//do some stuff and then
return new Obj; //obj is a class
}
int main()
{
Foo foo;
foo.pObj = CreateObj();
DoSomeOperationWithTheObj( foo.pObj );
//suppose foo is a monster that should be 'killed' or deleted now
delete foo.pObj;
foo.pObj = NULL;
//the question is can this pointer be 're-used' now like this:
foo.pObj = CreateObj(); //create another object
}
Поскольку указатель был удален, нет ли проблем с его повторным использованием, верно?
Obj* CreateObj() { //do some stuff and then return new Obj; //obj is a class }
int main() { Foo foo; foo.pObj = CreateObj(); DoSomeOperationWithTheObj( foo.pObj ); //suppose foo is a monster that should be 'killed' or deleted now delete foo.pObj; foo.pObj = NULL; //the question is can this pointer be 're-used' now like this: foo.pObj = CreateObj(); //create another object } [/code]
Поскольку указатель был удален, нет ли проблем с его повторным использованием, верно?