Re: [問題] class有static變數編譯不過
※ 引述《FreeF1y2 (FreeF1y2)》之銘言:
: 我用g++ 3.4.6編譯以下程式碼
: class TestClass {
: public:
: static int a;
: };
: int main() {
: TestClass c;
: c.a = 3;
: }
int TestClass::a; // 要在外面補上定義式。
: /var/tmp//cc2UNSTJ.o(.text+0x1e): In function `main':
: : undefined reference to `TestClass::a'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
要學會看懂 error message 才行,
這裡就是 a 沒定義所造成的 linking-time error。
--
Ling-hua Tseng (uranus@it.muds.net)
Department of Computer Science, National Tsing-Hua University
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Software pipelining for VLIW architectures
Homepage: https://it.muds.net/~uranus
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.225.100
推
08/11 23:13, , 1F
08/11 23:13, 1F
推
08/11 23:15, , 2F
08/11 23:15, 2F
推
08/12 00:24, , 3F
08/12 00:24, 3F
推
08/12 04:54, , 4F
08/12 04:54, 4F
→
08/12 04:55, , 5F
08/12 04:55, 5F
→
08/12 04:55, , 6F
08/12 04:55, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章