[問題] 初始化父類別連帶初始化子類別

作者: bulls5566 (公牛5566)   2018-03-15 13:17:28
開發平台(Platform): (Ex: Win10, Linux, ...)
macOS high Sierra
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
XCode
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
no
問題(Question):
我設一個父類別,並且能讓子類別可以overrride
然後在main function初始化父類別,並且藉由一些條件(終端機上的指令)來觸發子類別
但是最後出現bug,
Undefined symbols for architecture x86_64:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.6s with exit code 1]
想請教一下版上高手們,如何解決這問題
謝謝
餵入的資料(Input):

預期的正確結果(Expected Output):
子類別在條件觸發後,能成功初始化
錯誤結果(Wrong Output):
compile的時候出現錯誤訊息如下
Undefined symbols for architecture x86_64:
"ShortJobFirst::ShortJobFirst()", referenced from:
SchInitial(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in lab2-d65f71.o
"RR::RR(int)", referenced from:
SchInitial(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in lab2-d65f71.o
"FCFS::FCFS()", referenced from:
SchInitial(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in lab2-d65f71.o
"LCFS::LCFS()", referenced from:
SchInitial(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in lab2-d65f71.o
"PRIO::PRIO(int)", referenced from:
SchInitial(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in lab2-d65f71.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
https://ideone.com/ZskhiK
因為是一個練習scheduling的習題
所以不po全部的程式碼
僅就問題討論
補充說明(Supplement):
作者: stucode   2018-03-15 14:19:00
從錯誤訊息來看,應該是宣告了建構函數可是沒有給定義的關係。或是定義在鏈結器看不到的地方。
作者: steve1012 (steve)   2018-03-15 15:12:00
滑了一下你貼的 你並沒有寫 constructor阿

Links booklink

Contact Us: admin [ a t ] ucptt.com