为什么不允许将具有自己的标识符的结构声明为其元素?其中作为自引用结构,由带有指针符号的结构的同一变量声明!
这是我尝试过的代码:
#include<stdio.h>
#include<conio.h>
struct am
{
int a;
struct am k; // this reported an error
};
这段代码向我报告了一个错误,当我将它用作指针时,它接受了它,我搜索了网络,我发现它被称为自引用结构
#include<stdio.h>
#include<conio.h>
struct ko
{
int a;
struct ko * op; // this was allowed by my compiler
};
这个结构有效,请告诉我!
我使用的是 borland International inc. 的 TurboC++ 3.0 版。
最佳答案
一个对象不能包含与其自身类型相同的对象;这在逻辑上是不可能的,因为它需要比自身更大。
正如您所说,它可以包含指针或引用,但不能包含对象。
I'm using a TurboC++ version 3.0 by borland international inc.
我不知道为什么你会使用一个有二十年历史的编译器,以及现在很少有人记得的古老的 C++ 方言。但这在当时和现在都是不可能的。
关于c++ - 为什么不允许在其元素中使用结构变量本身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27424744/