如何访问在 c++ 中在类内声明的结构类型指针变量?
How to access structure type pointer variable which is declared inside the class in c++?
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;
}
相关文章:
- 在哪里声明结构运算符重载
- 如何正确转发声明结构"using XXX"?
- 在C++我可以在不在本地声明结构的情况下将结构作为指针传递吗?
- 在 for 循环中声明结构是否合法C++?
- 为什么我们可以创建一个模板类结构,其中包含许多与声明结构时指定的参数不同的参数
- 当声明结构数组时,CPPCHECK停止对整个文件的分析
- C++ - 声明结构和类时不允许使用不完整的类型
- 在声明末尾或 main 中声明结构或类实例之间的区别
- 在模板类中声明结构,未为成员函数定义
- C++ .h 文件中转发声明结构,并在.cpp文件中定义结构
- 如何在C++中声明结构变量
- 在 C 中声明结构的新实例
- 在类内部声明结构
- 为什么可以用相同的名称声明结构和非结构
- 在结构定义内部声明结构的堆栈
- 为什么在声明结构时不能初始化结构中的向量成员?
- 在c++头文件中声明结构体
- 如何声明结构体?
- c++中声明结构体的问题
- 只在库cpp中有定义的前向声明结构