我正在為迷宮求解程式實作圖形結構。我宣告了 2 個結構:vertex包含label標記該頂點,4 個方向edge;edge包含weight和vertex指向其他 4 個頂點的指標。
extern struct graph
{
int label;
struct Edge up;
struct Edge down;
struct Edge left;
struct Edge right;
}vertex;
extern struct Edge
{
int weight;
struct graph *neighbour;
}edge;
typedef struct graph vertex;
typedef struct Edge edge;
這種宣告方式會導致一些錯誤:unknown type name 'vertex'; 欄位“向上”的型別不完整,..
(我已經嘗試過,extern但似乎不是問題)。
那么我該如何正確宣告呢?
任何幫助,將不勝感激。
uj5u.com熱心網友回復:
不知道為什么 agraph也是 a Vertex,但您可以顛倒宣告 2 個結構的順序并使用前向宣告。您還可以組合結構宣告和型別定義。
struct graph; // Forward declaration
typedef struct
{
int weight;
struct graph *neighbour;
} edge;
typedef struct graph
{
int label;
edge up;
edge down;
edge left;
edge right;
} graph;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/464181.html
