Header file and extern keyword

前端 未结 5 2098
青春惊慌失措
青春惊慌失措 2021-01-22 21:06

I am having a lot of issue using extern variable and header files. I have read through sections of books and searched the web for hours but I haven\'t been able to figure out. A

5条回答
  •  一个人的身影
    2021-01-22 21:21

    You defined gI inside the scope of the main() function, which makes it visible only from there. I suspect what you really wanted is a global gI variable (hence the extern int gI declaration).

    If you want to have AnotherFunc() see it, move int gI = 0 outside, for instance in the same file than the definition of AnotherFunc().

提交回复
热议问题