Why, really, deleting an incomplete type is undefined behaviour?

后端 未结 6 1767
北荒
北荒 2020-11-30 06:07

Consider this classic example used to explain what not to do with forward declarations:

//in Handle.h file
class Body;

class Handle
{
   public:
           


        
6条回答
  •  佛祖请我去吃肉
    2020-11-30 06:37

    This is really just a special case of calling a method (the destructor, indirectly). delete impl_ effectively just calls the destructor and then the appropriate operator delete (global or class). You can't call any other function on an incomplete type, so why would delete's call to the destructor be given special treatment?

    The part I'm unsure about is what complication causes the standard to make it undefined instead of just forbidding it as in the method call.

提交回复
热议问题