【发布时间】:2019-07-13 18:26:41
【问题描述】:
我已经实现了一个名为 Customer 的类,这是头文件:它工作得很好。
现在,基于我的 Customer 类,我想实现一个 BST 树来存储客户信息,但我需要一个包含 Customer 对象、指向左孩子和右孩子的指针的节点类。我在正确实现 Node 类方面遇到了麻烦。特别是对于 Customer 对象。
class Customer {
public:
Customer(string,char,int);
string get_name();
char get_initial();
int get_account();
void set_account(int);
bool operator<(Customer & c);
bool operator<=(Customer & c);
bool operator>(Customer & c);
bool operator>=(Customer & c);
bool operator==(Customer & c);
bool operator!=(Customer & c);
private:
string name;
char initial;
int account;
friend ostream& operator<<(ostream & os, Customer & c);
};
#ifndef NODE_H_
#define NODE_H_
#include "Customer.h"
class Node {
public:
Customer parent;
Node* left;
Node* right;
};
#endif /* NODE_H_ */
显示的错误:被隐式删除,因为默认定义格式错误:
【问题讨论】:
-
如果不默认构造
Customer,就无法构造Node。但是,没有办法默认构造Customer。您只提供了Customer构造的机制,它需要参数。无论如何,此处发布的代码(以及仅此发布的代码)不会产生此类错误。您选择 not 包含的代码(您正在创建Node对象的位置)是事情最终开始偏离轨道的地方。 -
如果您阅读了整个错误消息,它应该会告诉您以上所有内容,您可能需要查看 IDE 的构建输出窗口