“给函数传入指针只是指针的副本”

太恶心了,今天居然被我碰上教科书上念叨的“给函数传入指针只是指针的副本”的问题,程序在下边(建立打印二叉树),程序写得很清晰明了,但是有一处小错误,谁找得出:

#include <iostream>
using namespace std;


class Node
{
public:
char m_data;
Node *m_left, *m_right;


Node( char data, Node *left = NULL, Node *right = NULL)
{
m_left = left;
m_right = right;
m_data = data;
}
};


class BTree
{
Node *m_root;


public:
BTree(Node *root = NULL)
{
m_root = root;
}


Node * Root()
{
return m_root;
}


void Create(Node *&p)
{
cout << "Please input a char, end input with '#'" << endl;
   char ch;
cin >> ch;
if('#' != ch)
{
p = new Node(ch);
Create(p-> m_left);
Create(p -> m_right);
}
}


void Create()
{
Create(m_root);
}


void Print(Node *p)
{
if(p != NULL)
{
cout << p -> m_data;
Print(p -> m_left);
Print(p -> m_right);
}
}


void Print()
{
Print(m_root);
}


/* void Clear(Node *p)
{
if(p != NULL)
{
Clear(p -> m_left);
Clear(p -> m_right);
delete p;
}
}*/


~BTree()
{
// Clear(m_root);
}
};


void main()
{
BTree btr;
btr.Create();
btr.Print();
}

你可能感兴趣的:(null,delete,Class,input)