C++中的类编译错误

Classes in C++ compilation error

本文关键字:编译 错误 C++      更新时间:2023-10-16

有人知道我为什么会出现这个错误吗?发帖前我真的很努力。非常感谢。

我得到

"In file included from familyRunner.cpp:7:0:
   familytree.h:22:40: error: expected identifier before ‘-’ token
    QuadraticHashTable<Human> hash_table(-1, 50000);" error.

class FamilyTree
{
public:
  FamilyTree(Family *families, int familyCount);
  void runQueries(Query *queries, Person *answers, int queryCount);
  QuadraticHashTable<Human> hash_table(-1, 50000);
};

这行看起来不对:

QuadraticHashTable<Human> hash_table(-1, 50000);

你不能用()进行内联初始化,你必须使用{}或=,例如:

QuadraticHashTable<Human> hash_table {-1, 50000};

或者,您可以在定义FamilyTree构造函数的cpp文件中初始化它。