此范围错误中未声明如何修复



我编写了一个代码来打印和查找 n 元树中节点的总和,但我收到一个错误,我无法修复它。

#include <iostream>
#include <queue>
using namespace std;
class Node
{
public:
Node(int input)
{
this->data = input;
}
vector<Node*> children;
int data;
};
void print(Node *root)
{
if (root == NULL)
return;
queue<Node *> q;
q.push(root);
int count = 0;
while (q.size() != 0)
{
Node *node = q.front();
cout << node->data << "  ";
q.pop();
int sum = 0;
for (unsigned int i = 0; i < node->children.size(); i++)
{
q.push(children[i]);
sum += (children[i]);
}
cout << " - ";
}
cout << "Sum: " << cout;
}
int main()
{
tree->children.push_back(new Node(16));
tree->children.push_back(new Node(96));
tree->children.push_back(new Node(8));
tree->children.push_back(new Node(10));
tree->children.push_back(new Node(22));
tree->children.push_back(new Node(9));
tree->children.push_back(new Node(100));
tree->children.push_back(new Node(1));
tree->children.push_back(new Node(51));
tree->children.push_back(new Node(70));
cout << "Root: " << tree->data << endl << "Children:" << endl;
for (unsigned int i = 0; i < 10; i++)
{
cout << tree->children[i]->data << " ";
}
cout << endl;
print (tree);
}

错误:"子项"未在此范围内声明 Q.推(儿童[i](; 我该如何解决它? 此错误的含义是什么?

假设您已经在此处包含所有代码。

在主"树"中从未创建过只是使用?然后子项不在范围之内,因为树从不在任何范围内。此外,如果您创建了另一个类来表示树及其在另一个文件中,则需要包含其定义的标头。

您尚未提供有关错误的行号或已采取的解决错误的步骤。

相关内容

  • 没有找到相关文章

最新更新