Re: [規格] 這東西合乎規格嗎 =_=a

看板C_and_CPP (C/C++)作者 (殺人貓™)時間16年前 (2009/03/23 01:27), 編輯推噓4(4013)
留言17則, 4人參與, 最新討論串2/2 (看更多)
※ 引述《Killercat (殺人貓™)》之銘言: 跟我想的一樣,這是VC自己extand的功能,完全不是標準裡面的東西... VC自己的stdafx.h(precompile header)裡面宣告的東西 即使沒有被真正的include進去 (事實上,每個.cpp都會被要求include stdafx.h..但是.h檔並沒有) 可是在每個header檔都會被參考到...即使該header壓根沒include他 所以只要在stdafx.h裡面include過或者宣告過, 就可以用在"任何一個.h,甚至沒有include stdafx.h"的header裡面 我就一直在想,為什麼他可以這樣寫我卻不行 打開stdafx.h以後才恍然大悟 -_- 前面幾個前置宣告也可以拿掉,那根本宣告心酸的 #pragma once //class irr::scene::IAnimatedMeshSceneNode; //class irr::scene::ISceneNode; //class Scripter::IScripterElement; struct CharImpl; //是的,即使程式完全沒有include半點東西也沒前置宣告,這個class仍然能過! //為什麼呢? 因為MS自己的stdafx.h太強大了! class CCharacters : public irr::scene::IAnimatedMeshSceneNode { private: CharImpl* m_pImpl; public: static const int MAX_FLAG = 24; CCharacters(ISceneNode* parent, ISceneManager* mgr, s32 id, const core::vector3df& position = core::vector3df(0,0,0), const core::vector3df& rotation = core::vector3df(0,0,0), const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f)); ~CCharacters(void); }; 是的,只要在stdafx.h裡面include過irr::scene::... 這邊完全連前置宣告都不用 整個code也沒有#include "stdafx.h" MS真是標準破壞者阿 囧 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.217.109.209 ※ 編輯: Killercat 來自: 61.217.109.209 (03/23 01:28)

03/23 02:15, , 1F
我一向都不使用 stdafx.h ^O^
03/23 02:15, 1F

03/23 02:32, , 2F
Irrlicht!!! 在寫什麼好玩的 XDDDDD
03/23 02:32, 2F

03/23 02:37, , 3F
快用 ogre!!
03/23 02:37, 3F

03/23 02:44, , 4F
ogre有在玩阿XD 可是Irrlicht跟RPGMaker一樣簡單
03/23 02:44, 4F

03/23 02:44, , 5F
所以忍不住先去玩玩Air lich(誤)
03/23 02:44, 5F
※ 編輯: Killercat 來自: 61.217.109.209 (03/23 02:47)

03/23 02:59, , 6F
XDDD 我當初也是覺得沒辦法掌握 Ogre ...
03/23 02:59, 6F

03/23 08:01, , 7F
VC要求每個cpp第一個include的必須是先行編譯標頭檔
03/23 08:01, 7F

03/23 08:03, , 8F
其他.h檔自然會在它之後. 其他編譯器只要能保證第一個要
03/23 08:03, 8F

03/23 08:04, , 9F
include的是某個東西,也可以做到這件事
03/23 08:04, 9F

03/23 08:05, , 10F
你直接去編譯.h就會出錯了,不過VC不讓你編譯.h檔就是了XD
03/23 08:05, 10F

03/23 16:45, , 11F
做不到,至少需要前置宣告...
03/23 16:45, 11F

03/23 16:46, , 12F
不然a.cpp有include "foo.h"就好了 a.h就不用作前置宣告
03/23 16:46, 12F

03/23 16:46, , 13F
class foo; 了阿
03/23 16:46, 13F

03/23 16:46, , 14F
現在VC是連前置宣告都幫你省了 你可以try看看 OTZ
03/23 16:46, 14F

03/23 16:47, , 15F
而且前置宣告並不允許直接慣namespace::在前面
03/23 16:47, 15F

03/23 19:32, , 16F
只要確保了include a.h 前一定會先include foo.h
03/23 19:32, 16F

03/23 19:34, , 17F
a.h就不需要做前置宣告了. 除非你單獨去編譯.h檔
03/23 19:34, 17F
文章代碼(AID): #19ndKV1V (C_and_CPP)
文章代碼(AID): #19ndKV1V (C_and_CPP)