下面是保存為diceroll.h的頭檔案
extern int roll_count;
int roll_n_dice(int dice,int sides);
創建了名為diceroll.c 的源檔案
在這個源檔案中定義了roll_n函式。
然后在主函式源檔案中包含了頭檔案
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include "diceroll.h"
編譯報錯,顯示未定義roll_n 函式。
如果加上#include “diceroll.c"就可以,那這樣頭檔案不就沒有意義了。
uj5u.com熱心網友回復:
看看是不是在diceroll.c檔案里面忘了包含diceroll.h。如果不是的話,看看是不是函式名打錯了。編譯報錯,顯示未定義roll_n 函式。 這里的roll_n函式和上面的roll_n_dice是同一個嗎? 是你簡寫了,還是報錯就是這樣報的?
uj5u.com熱心網友回復:
extern 這裡檢查下?這個說明在別的地方定義了 如果沒有 可能造成問題uj5u.com熱心網友回復:
這是diceroll.c的頭部#include "diceroll.h"
#include<stdio.h>
#include<stdlib.h>
在這個源檔案里面也定義了roll_n_dice函式
int roll_n_dice(int dice,int sides)
下面是保存為diceroll.h的頭檔案
extern int roll_count;
int roll_n_dice(int dice,int sides);
然后在主函式源檔案中包含了頭檔案
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include "diceroll.h"
編譯報錯,顯示未定義roll_n_dice 函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/105789.html
標籤:C語言
