[問題] 自訂class 沒辦法使用

看板C_and_CPP (C/C++)作者 (steve)時間14年前 (2011/12/04 10:58), 編輯推噓6(605)
留言11則, 6人參與, 最新討論串1/1
開發平台(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)

12/04 11:10, , 1F
因為 time 是標準函式庫中的函式,你撞名了
12/04 11:10, 1F
可是我也嘗試過 class name 改成 Time 和 TIME 也不行 C++不是 對大小寫會分辨嗎 要是換個名稱應該可以吧 ※ 編輯: steve1012 來自: 114.34.202.142 (12/04 11:28)

12/04 11:44, , 2F
我可以啊,你看看錯誤訊息吧
12/04 11:44, 2F
比如說我寫 time t; error message 要我在t前面加分號

12/04 11:47, , 3F
http://codepad.org/UGx0SEZU 這樣應該OK吧@@"
12/04 11:47, 3F
所以要使用自定義型別需要寫成 class time t; 不能time t;的意思嗎 ※ 編輯: steve1012 來自: 114.34.202.142 (12/04 12:08)

12/04 12:30, , 4F
在win下是不會分大小寫的~
12/04 12:30, 4F

12/04 12:32, , 5F
#include <cstdio> 跟 #include <CSTDIO> 個人在win下
12/04 12:32, 5F

12/04 12:32, , 6F
用gcc 都可以編譯過-.- 很神奇 orz
12/04 12:32, 6F

12/04 12:40, , 7F
C跟C++都是case sensitivity
12/04 12:40, 7F

12/04 12:41, , 8F
能include是因為windows的file sysyem不分大小寫
12/04 12:41, 8F

12/04 13:26, , 9F
沒猜錯的話,加了class可以讓編譯器辨識為類別而不是函數
12/04 13:26, 9F

12/04 13:43, , 10F
請愛用 namespaces...
12/04 13:43, 10F

12/05 13:10, , 11F
改個class名吧
12/05 13:10, 11F
文章代碼(AID): #1Esk7lbo (C_and_CPP)
文章代碼(AID): #1Esk7lbo (C_and_CPP)