The usage of extern in c++

后端 未结 2 844
無奈伤痛
無奈伤痛 2020-12-17 14:15

I\'ve having difficulty understanding how \'extern\' works. I\'ve searched Google but there doesn\'t seem to be the particular example case I\'m trying

If i have a f

2条回答
  •  情话喂你
    2020-12-17 15:02

    In C++, like C before it, each source file is compiled to an object file. Then all the object files are linked to create the executable program.

    To share symbols (functions, global variables), there are several keywords that tell the compiler which are local to the file, which are private, and which are imported from other file.

    The `extern' keyword means that a symbol can be accessed, but not defined. It should be defined (as a global) in some other module. If not, you get an 'undefined symbol' error at link time.

提交回复
热议问题