Is a destructor called when an object goes out of scope?

前端 未结 5 807
忘掉有多难
忘掉有多难 2020-11-28 23:37

For example:

int main() {
    Foo *leedle = new Foo();

    return 0;
}

class Foo {
private:
    somePointer* bar;

public:
    Foo();
    ~Foo();
};

Foo::         


        
5条回答
  •  时光取名叫无心
    2020-11-29 00:05

    In this instance, when main returns it's the end of the program, the Operating system will handle freeing all resources. If, for instance this was any other function, you would have to use delete.

提交回复
热议问题