作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
来自这里的 C++ 背景。我需要为我的一门类(class)编写 C 语言,但我从未接触过这一类(class)。这两个声明之间有什么区别?为什么要包含 struct 关键字?有不同的含义吗?它们在 C++ 和 C 中的含义是否不同?
struct A {
int dataA;
A* nextA;
};
struct B {
int dataB;
struct B* nextB;
};
下面的评论说第一个在 C 中无效。但是,我用 gcc 编译得很好。
编辑:我正在使用 gcc 编译 .cpp 文件。我真是个菜鸟哈哈。
解决方案:第二个对于 C 是必需的,而第一个仅在 C++ 中有效。
最佳答案
struct B {
int dataB;
B* nextB;
};
与
相同struct B {
int dataB;
struct B* nextB;
};
在 C++ 中,但在 C 中则不然。使用 C 时,您必须使用第二种形式。第一种形式不合法 C.
关于c++ - 有什么区别: Creating structure pointer inside a structure of the same type with the keyword struct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42049768/
我是一名优秀的程序员,十分优秀!