問題:
The question was about plain c functions, not c++ static
methods, as clarified in comments.問題是關於普通c函數,而不是c++ static
方法,如註釋中所述。
I understand what a static
variable is, but what is a static
function?我明白什麼是static
變量,但什麼是static
函數?
And why is it that if I declare a function, let's say void print_matrix
, in let's say ac
(WITHOUT ah
) and include "ac"
- I get "print_matrix@@....) already defined in a.obj"
, BUT if I declare it as static void print_matrix
then it compiles?爲什麼如果我聲明一個函數,讓我們說void print_matrix
,讓我們說ac
(沒有ah
)幷包含"ac"
- 我得到"print_matrix@@....) already defined in a.obj"
,但是如果我將它聲明爲static void print_matrix
那麼它會編譯嗎?
UPDATE Just to clear things up - I know that including .c
is bad, as many of you pointed out.更新只是爲了解決問題-正如你們中的許多人指出的那樣,我知道包括.c
是不好的。 I just do it to temporarily clear space in main.c
until I have a better idea of how to group all those functions into proper .h
and .c
files.我只是爲了暫時清除main.c
空間,直到我更好地瞭解如何將所有這些函數分組到正確的.h
和.c
文件中。 Just a temporary, quick solution.只是一個臨時的、快速的解決方案。
解決方案:
參考一: https://stackoom.com/question/2LBy參考二: What is a “static” function in C?