When to use extern in C++

前端 未结 4 2001
清歌不尽
清歌不尽 2020-11-22 03:15

I\'m reading \"Think in C++\" and it just introduced the extern declaration. For example:

extern int x;
extern float y;

I thi

4条回答
  •  甜味超标
    2020-11-22 03:35

    This is useful when you want to have a global variable. You define the global variables in some source file, and declare them extern in a header file so that any file that includes that header file will then see the same global variable.

提交回复
热议问题