结构成员之前"struct"和缺少"struct"单词有什么区别
What is the difference between "struct" and lack of "struct" word before member of a struct
我必须创建一个简单的列表实现。他们想把struct
放在Node
类的成员next
前面。为什么有一个struct
字,没有它会有什么不同?
struct Node{
int value;
struct Node *next;//what is this struct for?
};
struct List{
struct Node *first, *last;
};
在您的示例中,不需要在next
声明之前使用struct
关键字。它通常被认为是C语言的回退,在C语言中需要它。在c++中,这就足够了:
struct Node{
int value;
Node *next;
};
然而,如果你有一个名为Node
的成员,那么将不得不使用struct
或class
:
struct Node{
int Node;
struct Node *next; // struct or class required here
};
对于尚未定义的类型声明(前向声明),还需要struct
或class
。例如
struct Foo {
class Bar* bar_; // Bar defined later
};
我使用class
来显示它在这个场景中没有区别。
在next
之前不需要struct
。这应该是一个指向Node对象的简单指针。
相关文章:
- 文本文件中的单词链表
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 在指针的帮助下,文本文件中单词的频率
- 如何根据单词在文本中出现的概率输出单词
- C++Union/Struct位域的实现和可移植性
- 从字符串变量中逐字符读取单词
- 使用std::mt19937从字符串中返回一个随机单词
- 如何用for循环在c++中生成单词三角形
- 将数字转换为单词
- 如何在c++中定义以struct为数据成员的类中的构造函数
- 使用if-else将数字转换为单词
- C++-字符串是否包含一个带有简单循环的单词
- 使用单词"not"作为C ++类的名称会导致VS2019错误
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- 为什么这个程序返回最后一个单词而不是最长的单词?
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 3-3. 编写一个程序来计算每个不同单词在其输入中出现的次数
- C++为一串单词添加空格
- 结构成员之前"struct"和缺少"struct"单词有什么区别