This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。
6年前关闭。
我开始使用结构,创建了一个名为
我了解如何以通用方式进行操作-下面的
我在做错什么,或者怎么调试呢? (除了我的实施的整个概念,这是相当锻炼)。
或(很少见,但看起来像您尝试的那样)
或更确切地说,如何调试它?
“调试”是对成功构建的可执行文件执行的过程。您有编译器错误,因此调试不适用。
6年前关闭。
我开始使用结构,创建了一个名为
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);
}
最佳答案
我究竟做错了什么?tree
是类型LR*
的指针
可以使用以下语法从指针访问结构成员:
tree->L
或(很少见,但看起来像您尝试的那样)
(*tree).L
或更确切地说,如何调试它?
“调试”是对成功构建的可执行文件执行的过程。您有编译器错误,因此调试不适用。