How do I prevent a class from being allocated via the 'new' operator? (I'd like to ensure my RAII class is always allocated on the stack.)

后端 未结 4 1964
孤街浪徒
孤街浪徒 2020-11-28 07:26

I\'d like to ensure my RAII class is always allocated on the stack.

How do I prevent a class from being allocated via the \'new\' operator?

4条回答
  •  我在风中等你
    2020-11-28 08:02

    In my particular situation, if the lock isn't necessary the mutex doesn't even exist, so I think that approach would be rather harder to fit.

    I guess the thing I'm really struggling to understand is the justification for prohibiting creation of these objects on the free store.

提交回复
热议问题