作为c++开发,extern关键字


在C++中,`extern`关键字用于声明一个外部变量或函数。这意味着该变量或函数在当前文件中没有定义,但在其他文件中定义了。 例如,如果你有一个名为`myFunction`的函数,你可以在一个文件中声明它: ```cpp extern void myFunction(); ``` 然后在另一个文件中定义它: ```cpp void myFunction() { // function body } ``` 这样,你就可以在任何需要使用`myFunction`的文件中调用它,而不需要在每个文件中都定义它。 `extern`关键字也可以用于声明一个外部变量。例如: ```cpp extern int myVariable; ``` 然后在其他文件中定义它: ```cpp int myVariable = 42; ``` 这样,你就可以在任何需要使用`myVariable`的文件中访问它,而不需要在每个文件中都定义它。 [2023-11-09 00:45:14 | AI写代码神器 | 191点数解答]
相关提问
- #property link "http://wpa.qq.com/msgrd?v=3&uin=1567323819 &site=qq&menu=yes" #property copyright " QQ1567323819 →点击在线交流←" #include <stdlib.mqh> #include <WinUser32.mqh> // exported variables extern bool IndoRunLabelOn = true; //EA开关 extern string MagicNumber = "Random Magic will overide manual set Magic Number";//魔术码设置 extern int Magic = 123; //魔术码 extern bool UseRandomMagic = false; //开启随机魔术码 extern int RandomMagicLower = 100000; //随机小值 extern int RandomMagicUpper(34点数解答 | 2025-04-20 17:23:12)128
- #include <iostream> #include <fstream> #include <vector> #include <string> #include <sstream> #include <stack> #include <map> #include <cctype> using namespace std; const string preamble = R"( .intel_syntax noprefix .globl main .extern printf .section .data format_str: .asciz "%d\n" .section .text main: push ebp mov ebp, esp sub esp, 208 )"; const string postamble = R"( mov eax, 0 mov esp, ebp pop ebp ret )"; struct Variable { char name; int offset; }; v(2430点数解答 | 2025-07-10 21:28:43)70
- 在ios开发中,什么情况使用 weak 关键字,相比 assign 有什么不同?(311点数解答 | 2023-11-08 00:37:04)231
- 在ios开发中,怎么用 copy 关键字?(272点数解答 | 2023-11-08 00:37:13)236
- 在ios开发中,用@property声明的 nsstring / nsarray / nsdictionary 经常使用 copy 关键字,为什么?如果改用strong关键字,可能造成什么问题?(278点数解答 | 2023-11-08 00:37:19)361
- 在ios开发中,解释object-c什么情况使用 weak 关键字,相比 assign 有什么不同?(360点数解答 | 2023-11-09 17:38:45)273
- 作为**工程师,作为**工程师如何做到不漏测?(386点数解答 | 2023-11-09 18:25:11)266
- 作为c++开发,什么是c++的面向对象编程?(285点数解答 | 2023-11-09 00:36:11)222
- 作为c++开发,什么是虚函数?(289点数解答 | 2023-11-09 00:36:17)177
- 作为c++开发,什么是多线程?(64点数解答 | 2023-11-09 00:36:19)194
- 作为c++开发,什么是死锁?(61点数解答 | 2023-11-09 00:36:21)184
- 作为c++开发,什么是虚拟内存?(79点数解答 | 2023-11-09 00:36:23)200