如何访问在 c++ 中在类内声明的结构类型指针变量?

How to access structure type pointer variable which is declared inside the class in c++?

本文关键字:声明 结构 类型 变量 指针 何访问 访问 c++      更新时间:2023-10-16
class btree{
public:
int non,vor;
string str;
struct tree{
int data;
struct tree *lnode;
struct tree *rnode;
};
};
int main(){
}

如何在 Main 中访问结构类型指针 lnode,甚至可能提供帮助????

您定义了struct tree,但实际上并没有将任何内容放入您的btree中。请改为执行以下操作:

class btree {
public:
int non, vor;
string str;
struct tree {
int data;
struct tree *lnode;
struct tree *rnode;
} node; // note the "node" that was added, now btree contains a struct tree named "node"
};

像这样访问它:

int main() {
btree myTree;
myTree.node.data = 10;
}