c++ - 如何访问在 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;
}
推荐阅读
- regex - 正则表达式:匹配括号内可能包含或不包含嵌套括号的所有单引号或双引号字符串
- eclipse - Eclipse 通用文本编辑器排序大纲
- json - Presto Json 解析
- php - 如何使用套件谈话 Netsuite API 从保存的搜索中获取摘要
- azure - 所有者或参与者时的 Azure 策略排除
- c++ - 有没有办法将 Cython 扩展类型类属性定义为 C++ 类?
- types - 从文件加载程序集并调用 GetExportedTypes
- python - Spacy 3.0 的 nlp.update 问题:TypeError:[E978] Language.update 方法采用示例对象列表,但得到:{
} - c# - gRPC - 如果空闲时间过长,双向流将进入 TRANSIENT_FAILURE
- django - Django 自定义登录,如何将 ForeignKey 添加到 REQUIRED_FILED