看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) vs 2017 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) vc++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) stdlib 問題(Question): 1. 我有一個主程式, 以 main() 為入口點 因為這個主程式 main 會用到其他 class A, B, C main 本身要 include A, B, C .h 也要 include <iostream> ... 等等 但是 A, B, C.h 裡面也有 include 過 <iostream> 了 這樣會有問題嗎? 該如何避免這個問題呢 2. main 中需要 #define Length 透過編譯時給定參數 ex. @ main.cpp #ifndefine Length #define Length 100 #endif A, B, C.h 也都有上面這段 所以main include A.h, B.h, C.h 之後就重複了 請問有辦法避開嗎~ 謝謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.137.108.25 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1563782037.A.0AC.html
james732: google: include guard07/22 16:26
謝謝提供關鍵字
Gway: 你已經得到它了! #ifndefine #define #endifdefine07/22 16:46
Gway: #endif07/22 16:47
謝謝告知
Schottky: 上次的 lex 後來有順利解決嗎?07/22 17:54
有喔,謝謝你~ ※ 編輯: OfficeGL (114.137.108.25 臺灣), 07/22/2019 18:23:03 ※ 編輯: OfficeGL (114.137.108.25 臺灣), 07/22/2019 18:23:29
s4300026: #pragma once ? 07/22 21:03
loveme00835: 樓上的做法不好, 可以谷歌為什麼 07/22 22:07
LPH66: 個人以為 #pragma once 的缺點只有它是 de facto 標準 07/23 08:34
LPH66: (畢竟它本質上是 #pragma, 不會也不可能成為正式標準) 07/23 08:35
LPH66: 其他方面來說我會覺得使用方便性上和語意上都比正式做法好 07/23 08:38
BlazarArc: 同意樓上 07/23 18:54