我正在创建一个包含多个文件的程序,但它无法识别我的 tnode 文件中的 cout<<。谁能找到问题出在哪里?在其他错误中,我在我的节点文件中收到此错误“cout 未在此范围内声明”。我的主要功能:
#include <iostream>
#include "bst.h"
using namespace std;
int main(int argc, char *argv[]) {
cout<<"hi";
bst *list = new bst();
return 0;
}
我的 BinarySearchTree 文件:
#ifndef bst_H
#define bst_H
#include <iostream>
#include <string>
#include "tnode.h"
class bst
{
public:
bst()
{
root = NULL;
}
void add(int key, char value) {
if (root == NULL) {
root = new tnode(key, value);
return
} else
root->add(key, value);
return
}
tnode *root;
};
#endif
我的节点文件:
#ifndef tnode_H
#define tnode_H
#include <iostream>
#include <string>
class tnode
{
public:
tnode(int key, char value)
{
this->key = key;
this->value = value;
N = 1;
left = NULL;
right = NULL;
cout<<"hi";
}
void add(int key, char value) {
if (key == this->key)
{
cout<<"This key already exists";
return;
}
else if (key < this->key)
{
if (left == NULL)
{
left = new tnode(key, value);
cout<<"Your node has been placed!!";
return;
}
else
{
left->add(key, value);
cout<<"Your node has been placed!";
return;
}
}
else if (key > this->key)
{
if (right == NULL)
{
right = new tnode(key, value);
cout<<"Your node has been placed!!"; return;
}
else
return right->add(key, value);
}
return;
}
tnode* left;
tnode* right;
int key;
char value;
int N;
};
#endif