作者ric2k1 (Ric)
看板EE_DSnP
標題Re: [問題] hw1.2.1
時間Sun Oct 7 23:44:59 2012
※ 引述《jackervator (jokerlin)》之銘言:
: 請問一下
: hw1.2.1.a裡面的三個函數我可以放到1.2.1.b裡面再定義嗎?
: 這樣一來
: 我1.2.1.a全部放宣告
: 1.2.1.b全部放定義
: 看起來比較順眼(?)
: 其實主要原因是
: 如果我同時compile的話
: 然後我1.2.1.a三個函數是在class外另外宣告的話
: 最後的main
: 她會有ambiguous的情況(.a和.b都有 她不知道用哪個)
: 只是我在想說這樣會不會違反題目
: 想來問一下@@
先確定一下你有沒有清楚題目的規定 ---
1.2.1.a 應該會有三個檔案:
==========================
hw1.2.p1a.h // to define class P1a with the prototypes of its member functions
hw1.2.p1a.cpp // to define class P1a's member functions in a .cpp file
hw1.2.p1a.main.cpp // is the main() for this subproblem (provided)
當你 "make p1a" 的時候,以上三個檔案會被 compile, 產生 hw1.2.p1a 這個執行檔
而 1.2.1.b 所定義的那些 functions 並不是 class P1a 的 member functions,
而是用來檢查 memory addresses 的 global functions.
"make p1b" 只會 compile hw1.2.p1b.cpp 以及 hw1.2.p1b.main.cpp
不會 compile hw1.2.p1a.main.cpp
所以不會有你說的兩個 main 的問題啊!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.58.66
※ 編輯: ric2k1 來自: 114.36.58.66 (10/08 00:02)