我已经开始玩结构,我创建了一个我称之为LR
:
struct LR{
int v;
LR* L;
LR* R;
};
我了解如何以通用方式操作它 -main
下面的代码,在我开始构建类之前,我已经开始编写递归函数,它以字符串(“LRLRR”)的形式获取 LR 中节点的“地址”并返回需要LR,但我仍然从编译器中得到错误:
LR.cpp In function 'LR chooseNode(LR*, std::string)':
LR.cpp [Error] request for member 'L' in 'tree', which is of pointer type 'LR*'
(maybe you meant to use '->' ?)
- 部分带有递归的行错误chooseNode(*tree.L,str2);
我在做什么错,或者更确切地说如何调试它?(除了我的实施的整个概念,这是相当练习)。
#include<iostream>
#include<string>
#define SHOW(a) std::cout << #a << ": " << (a) << std::endl
using namespace std;
struct LR{
int v;
LR* L;
LR* R;
};
LR chooseNode(LR* tree, string str){// for example str="LRL"
// for clarity I've cutted the most of the code
if(str[0]=='L')
chooseNode(*tree.L,str2);
else if(str[0]=='R')
chooseNode(*tree.R,str2);
};
int main(){
LR d1,d2,d3;
d1.v=4;
d1.L=&d2;
(*(d1.L)).L=&d3;
d3.v=12345;
SHOW((*(*d1.L).L).v);
cout<<"Opis: "<<"\n";
SHOW(int(&d1));
SHOW(int(&d2));
SHOW(sizeof(d2.v));
return (0);
}