[問題] Link Error : Already Defined in main …

看板C_and_CPP (C/C++)作者 (YOYO)時間16年前 (2009/08/01 10:01), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
=== A.h === #ifndef A_H #define A_H class A { static int a; }; int A::a = 5; #endif ==A.cpp=== #include "A.h" ==main.cpp== #include "A.h" int main() {} 我用VC會出現Link error "public: static int A::x" (?x@A@@2HA) already defined in main.obj" 問題出在A.cpp也有#include A.h,我想問為什麼已經有宣告#ifndef了,還會重復進入呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.50.53.72

08/01 10:16, , 1F
11815討論串
08/01 10:16, 1F
※ 編輯: realmojo 來自: 123.50.53.72 (08/01 10:27)
文章代碼(AID): #1ASw7fbP (C_and_CPP)
文章代碼(AID): #1ASw7fbP (C_and_CPP)