类指针问题(高手请进)

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:43:59
定义一个类class BinaryTree{.....}
构造对象,且带参数BT(50)
定义类指针BinaryTree* pointer;
想让pointer 指向BT能做到吗?
我用BinaryTree* pointer=new BinartTree BT(50)或者用BT* pointer为什么都不行?高手指教一下

BinaryTree* pointer=new BinartTree
这是让指针变量pointer指向new出来的BinartTree 类的地址。
通过这个pointer,你就可以调用BT(50)了(BT是public函数)。写法是pointer->BT(50).
如果你的BT(50)是构造函数的话,那就直接
BinaryTree* pointer=new BinaryTree50)
此处的BT是BinaryTree的缩写

你new时写错了,不要加BT。构造函数与类同名。