看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Linux 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) g++ https://www.sendspace.com/file/55crup 上面網址是我程式碼 ... g++ AbstractOptimizationProblem.cpp main.cpp 我程式馬里面有用到 template 但是我不太熟template ! 懂的朋友可以幫我看一下原因! Thanks 下面是錯誤訊息 /tmp/ccQ0iTvh.o: In function `LocalLeastSquaresProblem::LocalLeastSquaresProblem(int, int, ConvergenceChecker<Evaluation>*)': main.cpp:(.text+0x28): undefined reference to `AbstractOptimizationProblem<Evaluation>::AbstractOptimizationProblem(int, int, ConvergenceChecker<Evaluation>*)' /tmp/ccQ0iTvh.o:(.rodata._ZTV24LocalLeastSquaresProblem[_ZTV24LocalLeastSquaresProblem]+0x10): undefined reference to `AbstractOptimizationProblem<Evaluation>::getEvaluationCounter()' /tmp/ccQ0iTvh.o:(.rodata._ZTV24LocalLeastSquaresProblem[_ZTV24LocalLeastSquaresProblem]+0x18): undefined reference to `AbstractOptimizationProblem<Evaluation>::getIterationCounter()' -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.181.255.94 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1506101475.A.142.html
kkmoon5566: 把constructor 設爲pure virtual function 09/23 02:22
kkmoon5566: AbstractOptimizationProblem(int maxEvaluations, in 09/23 02:22
kkmoon5566: t maxIterations, ConvergenceChecker<PAIR>* checker 09/23 02:22
kkmoon5566: <PAIR>* checker)=0; 09/23 02:23
yshihyu: AbstractOptimizationProblem.h:10:5: error: initialize 09/23 02:29
yshihyu: specified for non-virtual method 09/23 02:29
yshihyu: 改成 = 0 編譯變成這樣錯誤 09/23 02:30
kkmoon5566: 講錯了= =" sorry 09/23 11:48
kkmoon5566: 這樣好像可以了~ https://pastebin.com/x7csU8Cd 09/23 20:28
kkmoon5566: 原因是compiler不知道template class要支持什麼data 09/23 20:32
kkmoon5566: as the compiler does not know, while compiling Sta 09/23 20:32
kkmoon5566: ck.cpp by itself, the data types it should provide 09/23 20:32
kkmoon5566: support for. 09/23 20:33
kkmoon5566: 來源:https://tinyurl.com/y7qlx77b 09/23 20:33
yshihyu: 嗯嗯~有部份錯誤有解! 不過 main.cpp:(.text+0x28): un 09/24 01:57
yshihyu: AbstractOptimizationProblem<Evaluation>::AbstractOpti 09/24 01:58
yshihyu: ::AbstractOptimizationProblem(int, int, ConvergenceCh 09/24 01:58
yshihyu: 我在main.cpp 把 AbstractOptimizationProblem(maxEvalua 09/24 02:00
yshihyu: 改成 AbstractOptimizationProblem<Evaluation>(maxEvalu 09/24 02:00