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

前端 未结 5 747
谎友^
谎友^ 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:46

    Because when instance goes out of scope, it has to be destructed using destructor. Pointer to instance does not do this.

提交回复
热议问题