[問題] static用法

作者: oToToT (屁孩)   2018-11-22 00:11:53
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux, OS X
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
g++-8 (Homebrew GCC 8.2.0) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
g++ (GCC) 8.1.1 20180531
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)

問題(Question):
剛剛發現這份程式碼用我手邊的編譯器都編不過,但是丟到一些較舊的編譯器卻編的過
而自己要讓他編的過則要把static拿掉(改成 const int INF = 1000000000)才會過
之前一直以為static只是會讓class共用一個實體,不會每一個都重新生成而已,但好像
又不太對,不知道static該如何準確理解呢?
餵入的資料(Input):

預期的正確結果(Expected Output):
編譯成功
錯誤結果(Wrong Output):
Undefined symbols for architecture x86_64:
"KuhnMunkres::INF", referenced from:
KuhnMunkres::solve() in ccXZSn3o.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
https://gist.github.com/oToToT/e16c9e8a68661fa980a0c827c907d8e8
補充說明(Supplement):
上面列的三個編譯器都不能順利編譯,但我用了Codeforces的跟Ideone提供的編譯器都可
以順利編譯
作者: kokal (細菌)   2018-11-22 00:33:00
c++ structure的static variable 要另外宣告-INF?

Links booklink

Contact Us: admin [ a t ] ucptt.com