Delete objects of incomplete type

前端 未结 3 2008
孤街浪徒
孤街浪徒 2020-12-06 16:02

This one made me think:

class X;

void foo(X* p)
{
    delete p;
}

How can we possibly delete p if we do not even know whether

3条回答
  •  [愿得一人]
    2020-12-06 17:01

    It is undefined behaviour, and a common gotcha when implementing the pImpl pattern. To the best of my knowledge, there is simply no such thing as a warning that the compiler is required to emit. Warnings are elective; they're there because the compiler writer thought they would be useful.

提交回复
热议问题