错误背后的原因? [英] Reason behind error?
本文介绍了错误背后的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<iostream>
using namespace std;
typedef struct student stud
{
int rno;
stud *s;
}
int main()
{
s->rno=30;
cout<<s->rno;
return 0;
}
我的尝试:
这个程序显示错误,因为我们无法在内存存在之前为内存提供替代名称。如果是这种情况,那么即使在结构定义之后我们也无法使用typedef,因为在创建变量时会创建结构内存吗?
我的问题是:
是否可以使用typedef关键字创建自我重构结构?
What I have tried:
is this program showing error because we can't give an alternative name to a memory before its existence.If this is the the case then we couldn't have been able to use typedef even after structure definition, since a structure memory is created when it's variable is created?
my question is:
is it possible to create self-refrential structure using typedef keyword?
推荐答案
该程序显示错误,因为有错误...
请注意您不需要typedef struct
s inC ++
。
尝试
The program is showing errors because there are errors...
Please note you don't need totypedef struct
s inC++
.
Try
#include<iostream>
using namespace std;
struct stud
{
int rno;
stud *s;
};
int main()
{
stud * s = new stud();
s->rno=30;
s->s = nullptr;
cout << s->rno <<endl;
delete s;
return 0;
}
这篇关于错误背后的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文