如果我想创建一个可以容纳2个双精度的变量Point并且我想避免每次使用它时都要编写struct我可以简单地使用:
typedef struct{
double x,y;
}Point;
但是当我想制作一个链表时,声明必须是这样的:
typedef struct Node Node; // (2)
struct Node{
int d;
struct Node * next;
};
而不是这样:
typedef struct{
int d;
struct Node * next;
}Node;
为什么声明必须是这样的,为什么你必须键入" Node"两次,见(2)。
答案 0 :(得分:1)
<!DOCTYPE html>
<html>
<head>
<script>
function Function1() {
document.getElementById("demo").innerHTML = "<img>imagelinkgoeshere</img>"
}
</script>
</head>
<body>
<button style="width:100px;font-size:20px;font-family:Playball;color:#910000;background-color:rgba(0,0,0,0);border:solid 0px #fff" onclick="Function1()">Theme1</button>
<p id="demo">Photos appear here</p>
</body>
</html>
此语句是编译器将typedef struct Node Node;
与Node
同名的指令,这就是为什么它必须包含单词&#34; Node&#34;两次。
声明也不一定要这样,第二个版本也是正确的。
struct Node
声明根本不必包含struct
,只需要为类型指定新名称,并且通常与typedef
声明一起使用以避免需要一遍又一遍地输入单词struct
。