Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未定义符号:某个类的vtable_C++_Virtual Functions - Fatal编程技术网

C++ 未定义符号:某个类的vtable

C++ 未定义符号:某个类的vtable,c++,virtual-functions,C++,Virtual Functions,刚刚遇到了以下两个叮当作响的错误: ld.lld: error: undefined symbol: vtable for HashFn >>> referenced by hashFn.h:40 ...... HashFn::HashFn(int, bool) 及 hashFn.h--> 出了什么问题?我可以模糊地理解这与虚拟析构函数有关,但不确定为什么vtable是未定义的(如果我定义了所有声明,那么vtable应该自动存在?) 另外,我现在正在使用Chromium,所以

刚刚遇到了以下两个叮当作响的错误:

ld.lld: error: undefined symbol: vtable for HashFn
>>> referenced by hashFn.h:40 ......
HashFn::HashFn(int, bool)

hashFn.h-->

出了什么问题?我可以模糊地理解这与虚拟析构函数有关,但不确定为什么vtable是未定义的(如果我定义了所有声明,那么vtable应该自动存在?)

另外,我现在正在使用Chromium,所以我不知道所有文件都编译成“jumbo”对象这一事实会如何影响结果。此代码()的独立版本可以正常编译和运行


欢迎您的任何意见!谢谢。

您是否在某个地方提供了
运算符()
的定义?@Oliv Yes在相应的.cc文件中,带有两个签名。因此这是不正常的,clang应该在定义
运算符()
的对象文件中定义vtable。析构函数是否为虚拟的事实不应改变这一点。请提供一个.hmmm。。。我对C++很陌生,所以我的头脑里也没有其他线索。另一件事是,我实际上在Chromium的代码库中开发,所以这个目录中的所有文件都被编译并链接到一个“jumbo”对象文件。虽然我想这根本就不应该是床垫?
ld.lld: error: undefined symbol: vtable for HashFn
>>> referenced by hashFn.h:36 ......
HashFn::HashFn(HashFn const&)
#ifndef HASHFN_H_
#define HASHFN_H_

#include "./base.h"

typedef uint64_t uint64Array[30];
static int precomputedArraySize = sizeof(uint64Array) / sizeof(uint64_t);

inline uint64_t customPow(uint64Array *precomputedPowers, bool usePrecomputed,
    uint64_t base, int exp) {
  if (usePrecomputed && exp < precomputedArraySize) {
    return (*precomputedPowers)[exp];
  }

  // TOOD: Optimization possible here when passed in toSize which is bigger
  // than precomputedArraySize, we can start from the value of the last
  // precomputed value.
  uint64_t result = 1;
  while (exp) {
    if (exp & 1)
      result *= base;
    exp >>= 1;
    base *= base;
  }
  return result;
}


// Functor for a hashing function
// Implements a Rabin fingerprint hash function
class HashFn {
 public:
  // Initialize a HashFn with the prime p which is used as the base of the Rabin
  // fingerprint algorithm
  explicit HashFn(int p, bool precompute = true) {
    this->p = p;
    this->precompute = precompute;
    if (precompute) {
      uint64_t result = 1;
      for (int i = 0; i < precomputedArraySize; i++) {
        precomputedPowers[i] = result;
        result *= p;
      }
    }
  }
  //virtual ~HashFn(){}
  ~HashFn(){}

  virtual uint64_t operator()(const char *input, int len,
      unsigned char lastCharCode, uint64_t lastHash);

  virtual uint64_t operator()(const char *input, int len);

 private:
  int p;
  bool precompute;
  uint64Array precomputedPowers;
};

#endif  // HASHFN_H_
#include "hashFn.h"

uint64_t HashFn::operator()(const char *input, int len,
      unsigned char lastCharCode, uint64_t lastHash) {
    // See the abracadabra example:
    // https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm
    return (lastHash - lastCharCode *
      customPow(&precomputedPowers, precompute, p, len - 1)) *
      p + input[len - 1];
  }

uint64_t HashFn::operator()(const char *input, int len) {
    uint64_t total = 0;
    for (int i = 0; i < len; i++) {
      total += input[i] *
        customPow(&precomputedPowers, precompute, p, len - i - 1);
    }
    return total;
  }
class HashFn2Byte : public HashFn {
 public:
  HashFn2Byte() : HashFn(0, false) {
  }

  uint64_t operator()(const char *input, int len,
      unsigned char lastCharCode, uint64_t lastHash) override;

  uint64_t operator()(const char *input, int len) override;
};
......