为什么不允许声明具有自己的标识符的结构作为其元素?作为一个自引用结构,由结构的同一个变量用指针符号声明!
这是我试过的代码:
#include<stdio.h>
#include<conio.h>
struct am
{
int a;
struct am k; // this reported an error
};
Run Code Online (Sandbox Code Playgroud)
这段代码报告了一个错误,当我用它作为指针接受它时,我搜索了网络,我开始知道它被称为自引用结构
#include<stdio.h>
#include<conio.h>
struct ko
{
int a;
struct ko * op; // this was allowed by my compiler
};
Run Code Online (Sandbox Code Playgroud)
这个结构工作请告诉我!
我正在使用borland international inc的TurboC++ 3.0版.
对象不能包含与其自身相同类型的对象; 这是一个逻辑上的不可能,因为它需要比自己更大.
如你所说,它可能包含指针或引用,但不包含对象.
我正在使用borland international inc的TurboC++ 3.0版.
我不知道为什么你会使用一个二十年前的编译器,以及现在很少有人记得的C++古老方言.但这和现在一样不可能.
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |