[問題] Function templates的問題

作者: david830317 (dd810)   2016-02-24 13:37:05
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VS2010
問題(Question):
怎麼在一個function template裡比較數字跟字串長度
預期的正確結果(Expected Output):
字串部分可以跑出最長的,可是都是跑出第二個
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
http://ideone.com/sseR06
補充說明(Supplement):
有想過許多辦法可是就是沒辦法出現預期的結果...
有想過先用strlen來取得長度再來比較
不過最後都只出現長度OTZ
作者: MasTerNBHD (NBHD)   2016-02-24 15:04:00
string 長度那邊用.length()做比較,可能要另外再定義
作者: shadow0326 (非議)   2016-02-24 16:11:00
string operator< 不是用來比較長度的呀
作者: CaptainH (Cannon)   2016-02-24 20:51:00
多傳一個cmp functor進去
作者: fightforlive (學歷無用論是屁)   2016-02-26 20:34:00
'y'>'h' 大大

Links booklink

Contact Us: admin [ a t ] ucptt.com