Fly*_*s00 2 c++ operator-overloading
我有一个这个树类:
#include <fstream>
using namespace std;
#ifndef HUFF_TREE_H
#define HUFF_TREE_H
class HuffTree{
public:
HuffTree();
HuffTree(char data, float frequency);
~HuffTree();
HuffTree& operator = (const HuffTree& tree);
int getNumberNodes();
float getFrequency();
void merge(HuffTree *tree);
friend ostream& operator << (ostream &out, const HuffTree &tree);
private:
struct node{
char data;
float frequency;
node* left;
node* right;
};
node* head;
int number_nodes;
float avg_code_length;
void destroy(node* &head);
void copyTree(node* &t1, node* t2);
};
#endif
Run Code Online (Sandbox Code Playgroud)
这是重载输出运算符的代码:
ostream& operator << (ostream &out, const HuffTree &tree){
out << "testing";
return out;
}
Run Code Online (Sandbox Code Playgroud)
在我的主函数中,我调用函数如下:
HuffTree* tree;
cout << tree;
Run Code Online (Sandbox Code Playgroud)
从我读过的内容来看,这应该可行,但我在屏幕上打印了十六进制数字。上面的例子打印出“0x1dcc2b0”。如果我将文件句柄传递给它,也会发生同样的事情。我想我只需要一双新的眼睛,有人能看到我的问题吗?
| 归档时间: |
|
| 查看次数: |
592 次 |
| 最近记录: |