C++ Learning 2
Typical usage of autoptr
typedef auto_ptr<TypeName> TypeNamePtr;
TypeNamePtr func1() {
TypeNamePtr p(new TypeName());
return p;
}
void func2() {
TypeNamePtr p = func1();
p.DoSth();
}
And if without auto_ptr, func2 should delete p finally, but now we just ignore this step, it
will be automatically released.
0 Comments:
Post a Comment
<< Home