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

看板C_and_CPP作者 (公牛5566)時間7年前 (2018/03/15 05:17), 編輯推噓1(102)
留言3則, 2人參與, 7年前最新討論串1/1
開發平台(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): 無 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 98.109.153.150 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1521091052.A.79C.html

03/15 14:19, 7年前 , 1F
從錯誤訊息來看,應該是宣告了建構函數可是沒有給定義的
03/15 14:19, 1F

03/15 14:19, 7年前 , 2F
關係。或是定義在鏈結器看不到的地方。
03/15 14:19, 2F

03/15 15:12, 7年前 , 3F
滑了一下你貼的 你並沒有寫 constructor阿
03/15 15:12, 3F
文章代碼(AID): #1QgW7iUS (C_and_CPP)