++ , - , , . , , , .. ~ MyClass.
void foo() {
MyClass object;
object.makeWonders();
}
If you declare a pointer to a function, then the pointer itself (4 bytes for 32-bit systems) gets corrected when it leaves the scope, but the memory that you could allocate using the new or malloc operator will be delayed - this is often known as memory leak.
void foo() {
MyClass* object = new MyClass;
object->makeWonders();
}
If you really have to select an object through a new one that needs to be deleted when it leaves the scope, then you should use boost :: scoped_ptr, for example:
void foo() {
boost::scoped_ptr<MyClass> object(new MyClass);
object->makeWonders();
}
source
share