C++, preventing class instance from being created on the stack (during compiltaion)

前端 未结 5 748
谎友^
谎友^ 2020-12-29 00:29

I know there are methods to prevent a class from being created on the heap, by preventing the user from using the new and delete operator. I am try

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 00:41

    Whenever a local variable goes out of scope, it is destroyed. And on destruction, destructor of object is called. Here, scope is of main function. When program exits, myclass object's destructor will be called

提交回复
热议问题