我真的卡住了,我在"CTree.add(num);"收到错误 说'CTree'是未声明的,这没有意义,因为我在tree.h中初始化它?
该程序应该提示用户,用户输入一个命令(即"添加3",只有0-9个整数),然后我希望它将该数字插入树中.
//File: tree.h
class CTree
{
private:
CTree* m_pLeft;
CTree* m_pRight;
CTree* m_pRoot;
int m_nData;
public:
CTree();
bool isEmpty() const { return m_pRoot; }
bool search(int);
void print_inorder();
void inorder(CTree*);
void Add(int);
void remove(int);
void height();
};
//File: CTree.cpp
#include <iostream>
#include <cstdlib>
using namespace std;
CTree::CTree()
{
m_pRoot=NULL;
}
bool CTree::search(int x)
{
if(x==m_nData) return true;
if(x < m_nData){ //go left
if(m_pLeft != NULL) //if possible
return m_pLeft->search(x);
}
else //go right
if(m_pRight != NULL) //ifpossible
return …Run Code Online (Sandbox Code Playgroud) 这真的令人沮丧,我尝试了我的类和构造函数的多种变体,通过谷歌搜索结果和本网站上的其他问题进行筛选,但我无法弄清楚.我相信这个错误很简单,我忽略了.
错误代码:
1>main.cpp(60): error C2065: 'Student' : undeclared identifier
1>main.cpp(60): error C2146: syntax error : missing ';' before identifier 'newStudent'
1>main.cpp(60): error C3861: 'newStudent': identifier not found
Run Code Online (Sandbox Code Playgroud)
student.h
#ifndef STUDENT_H
#define STUDENT_H
class Student {
private:
static const int SIZE = 7; // initial size of the array
int *Students; // Students will point to the dynamically allocated array
//int numStudents; // number of students currently in the list
int rosterSize; // the current size of the roster
int student_id; …Run Code Online (Sandbox Code Playgroud)