Why does this virtual destructor trigger an unresolved external?

前端 未结 7 1533
情书的邮戳
情书的邮戳 2021-02-19 03:43

Consider the following:

In X.h:

class X
{
    X();
    virtual ~X();
};

X.cpp:

#inclu         


        
7条回答
  •  温柔的废话
    2021-02-19 04:07

    You may be getting away with this because both constr and destr are private - if there is no other ref to class X in your build then the compiler may be deducing that the destr is not required, so lack of a definition is no biggie.

    This does not explain to me why case 1 fails while 2 and 3 build OK though. Wonder what happens if both are made public?

提交回复
热议问题