c++ - 编译器无法识别构造函数,需要参数并识别零
问题描述
我正在尝试将数据组织成二叉树,并创建了一个结构来更好地组织数据。但是,每次我尝试运行我的代码时,我的编译器都会出现此错误消息:
BinaryTree.cpp:41:37: error: no matching function for call to 'person::person()'
node (person i, node * l, node * r){
^
BinaryTree.cpp:14:2: note: candidate: 'person::person(int, int, std::__cxx11::string, std::__cxx11::string, int)'
person(int ss, int bd, string fn, string ln, int zc) {
^~~~~~
BinaryTree.cpp:14:2: note: candidate expects 5 arguments, 0 provided
BinaryTree.cpp:10:8: note: candidate: 'person::person(const person&)'
struct person {
^~~~~~
BinaryTree.cpp:10:8: note: candidate expects 1 argument, 0 provided
BinaryTree.cpp:10:8: note: candidate: 'person::person(person&&)'
BinaryTree.cpp:10:8: note: candidate expects 1 argument, 0 provided
它所指的代码行是我创建的这些结构。我以前使用过 person 结构,它工作得很好,所以我对我的错误感到困惑。
struct person {
int socialSecurity, birthDate, zipCode;
string firstName, lastName;
person(int ss, int bd, string fn, string ln, int zc) {
socialSecurity = ss;
birthDate = bd;
firstName = fn;
lastName = ln;
zipCode = zc;
}
};
struct node {
person info;
node * left, * right;
node (person i, node * l, node * r){
info = i;
left = l;
right = r;
}
};
我对此有点陌生,所以如果您需要更多代码来帮助我找出问题所在,我会尽力提供。
解决方案
由于您定义了非默认构造函数,编译器不会生成默认构造函数,请参阅https://en.cppreference.com/w/cpp/language/default_constructor了解更多信息。要解决这个问题,请参阅未生成默认构造函数?.
推荐阅读
- node.js - 是否可以用 NodeJS 连接 3 个不同的数据库?如果是,那么如何
- android - 如何销毁 Ui android Studio
- excel - 流口水在 excel 文件中添加事实类型(声明类型)
- javascript - Javascript 中的堆排序实现
- list - Haskell如何删除列表中的所有0直到元素之一/ = 0?
- python - 为什么我的 Tensorflow 模型无法预测简单的 2 次二次方程?
- java - 了解 setPresistanceEnabled(true) 和 keepSynced(true)
- git - Git 没有检测到同一行的代码冲突
- python - 在 Python Flask 中读取包含由分隔符分隔的数据的 csv 文件
- python-3.x - 如何从 json 文件中删除 \n