Public operator new, private operator delete: getting C2248 “can not access private member” when using new

前端 未结 5 794
自闭症患者
自闭症患者 2020-11-27 22:33

A class has overloaded operators new and delete. new is public, delete is private.

When constructing an instance

5条回答
  •  自闭症患者
    2020-11-27 23:20

    Calling operator new on class will use also delete class if class constructor throws an exception.

    If your library does not use exceptions, you can disable exceptions from compiler "-fno-exceptions", then error won't appear anymore. (In Visual studio resides under "C/C++", "Code Generation", "Enable C++ Exceptions" > "No (-fno-exceptions)")

提交回复
热议问题