gpt4 book ai didi

c++ - "Missing vtable"为析构函数,但析构函数已定义

转载 作者:行者123 更新时间:2023-11-28 02:07:09 24 4
gpt4 key购买 nike

我有一个类:

class Optimizer {
public:
Optimizer(mongoc_client_t *dbClient, std::string strategyName, std::string symbol, int group);
virtual ~Optimizer() = 0;

及其实现:

#include "optimizers/optimizer.h"

Optimizer::Optimizer(mongoc_client_t *dbClient, std::string strategyName, std::string symbol, int group) {
// ...
}

Optimizer::~Optimizer() {
free(data);
}

但我收到以下错误,似乎与未定义的析构函数有关:

Undefined symbols for architecture x86_64:
"typeinfo for Optimizer", referenced from:
typeinfo for ReversalsOptimizer in reversalsOptimizer.o
"vtable for Optimizer", referenced from:
Optimizer::Optimizer(_mongoc_client_t*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int) in optimizer.o
Optimizer::~Optimizer() in optimizer.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [prepareData] Error 1

我做错了什么?完整的 header 定义是 here实现是here .

我也试过使析构函数成为非虚拟的,但没有帮助。

最佳答案

问题正是错误消息所说的:

NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

具体来说,您声明并调用了但从未定义此函数:

    virtual void prepareStudies();

关于c++ - "Missing vtable"为析构函数,但析构函数已定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37041302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com