Re: [問題] extern const array?
看板C_and_CPP (C/C++)作者saxontai (黑暗,點綴孤零零的星)時間12年前 (2013/08/17 05:53)推噓1(1推 0噓 0→)留言1則, 1人參與討論串2/3 (看更多)
※ 引述《QQ29 (我愛阿蓉)》之銘言:
: 無意間遇到
: extern const int array[];
: 以我觀念
: 我會再.cpp寫
: const int array[NUM] = {...}
: link error...
: 多方嘗試
: extern const int array[NUM] = {...}
: 離奇的成功了
: 但我不解為啥會需要這樣改
: 該怎麼解釋...
: 另外const int 寫在.h 給多個cpp include後
: 不會爆 redefine 是因為 const 他若多份 就會變成類似static嗎?
: 因為我看address都不同
: 請各位解惑
: 謝謝~
C++ Primer 4/e
Part I: The Basics
Section 2.4. const Qualifier
const Objects Are Local to a File By Default
...
...
We'll see in Section 2.9.1 (p.69) why const objects are
made local to a file.
Note: Nonconst variables are extern by default.
To make a const variable accessible to other files we must explicitly
specify that it is extern.
Section 2.9.1. Designing Our Own Headers
...
...
不打了,自己去看。XD
--
Need Help With Women? Can UNIX Help?
$> man woman
$> Segmentation fault (core dumped)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 223.138.250.80
※ 編輯: saxontai 來自: 223.138.250.80 (08/17 05:53)
推
08/17 18:00, , 1F
08/17 18:00, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章