看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 自己寫了一個time.h 問題(Question): 我是在練習class的時候 屢屢遭受到一個奇怪的問題 我add 一個class 叫做 time 我也編輯好time.h 和time.cpp 也將time.cpp compile過了 可是當我在主程式中要用time來宣告一個物件的時候卻沒有辦法 我有include time.h 不知道為什麼會發生這種事情 我是漏了什麼步驟嘛? 我也用dev c++示過了 遇到一模一樣的問題 下面是我練習的time 的headerfile 和 cpp檔案 time.h http://codepad.org/WSfGEUZT time.cpp http://codepad.org/d5SGNzsI -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.34.202.142 ※ 編輯: steve1012 來自: 114.34.202.142 (12/04 11:04)
littleshan:因為 time 是標準函式庫中的函式,你撞名了 12/04 11:10
可是我也嘗試過 class name 改成 Time 和 TIME 也不行 C++不是 對大小寫會分辨嗎 要是換個名稱應該可以吧 ※ 編輯: steve1012 來自: 114.34.202.142 (12/04 11:28)
littleshan:我可以啊,你看看錯誤訊息吧 12/04 11:44
比如說我寫 time t; error message 要我在t前面加分號
s3748679:http://codepad.org/UGx0SEZU 這樣應該OK吧@@" 12/04 11:47
所以要使用自定義型別需要寫成 class time t; 不能time t;的意思嗎 ※ 編輯: steve1012 來自: 114.34.202.142 (12/04 12:08)
cuteclare:在win下是不會分大小寫的~ 12/04 12:30
cuteclare:#include <cstdio> 跟 #include <CSTDIO> 個人在win下 12/04 12:32
cuteclare:用gcc 都可以編譯過-.- 很神奇 orz 12/04 12:32
BombCat:C跟C++都是case sensitivity 12/04 12:40
BombCat:能include是因為windows的file sysyem不分大小寫 12/04 12:41
s3748679:沒猜錯的話,加了class可以讓編譯器辨識為類別而不是函數 12/04 13:26
uranusjr:請愛用 namespaces... 12/04 13:43
flylover:改個class名吧 12/05 13:10