Will an 'empty' constructor or destructor do the same thing as the generated one?

前端 未结 7 1412
一生所求
一生所求 2020-11-28 18:49

Suppose we have a (toy) C++ class such as the following:

class Foo {
    public:
        Foo();
    private:
        int t;
};

Since no des

7条回答
  •  粉色の甜心
    2020-11-28 19:30

    An empty definition is fine since the definition can be referenced

    virtual ~GameManager() { };
    The empty declaration is deceptively similar in appearance
    virtual ~GameManager();
    yet invites the dreaded no definition for virtual destructor error
    Undefined symbols:
      "vtable for GameManager", referenced from:
          __ZTV11GameManager$non_lazy_ptr in GameManager.o
          __ZTV11GameManager$non_lazy_ptr in Main.o
    ld: symbol(s) not found

提交回复
热议问题