C/C++??extern????????
???????????? ???????[ 2015/2/13 16:09:44 ] ????????C++ ??????? ????
????5 ????extern ????????
??????????extern???????????????????????????????????C?????????extern??????????????????????
?????????????
??????????????????д??й????extern????????????????????????????????壬??????????á???????????????????????????????
????extern int f(); ??int f();
???????????????????????е??????????????include “*.h”???????????????Щ?????????У?????????????е????????????extern???Ρ????????????????????????????????????“??extern???ε???????”
????(1) ??test1.h????????????:
????#ifndef TEST1H
????#define TEST1H
????extern char g_str[]; // ??????????g_str
????void fun1();
????#endif
????(2) ??test1.cpp??
????#include "test1.h"
????char g_str[] = "123456"; // ??????????g_str
????void fun1() { cout << g_str << endl; }
????(3) ??????test1??飬 ????????????????????????????????test2?????????g_str???????????????????????
????#include "test1.h"
????void fun2() { cout << g_str << endl; }
????????test1??test2?????????????????????????????????????ultraEdit??test1.obj????????????????"123456"???????????????????????test2.obj????????????????g_str???????????????????????????????????test2.obj?????????????????????????????????????????????????????!
????(4) ??Щ????????????????????????????????????????????????壬???????test1.h???
????extern char g_str[] = "123456"; // ?????????????extern
????????test1.cpp?е?g_str????????????????????????test1??test2???????????????????????????????????g_str?????????????????test1.cpp???????????test1.h????????????g_str????test2.cpp???????test1.h????????ζ?????g_str????????????????????test1??test2?????????g_str???????????g_str????????test1.h?е?????????test2???????#include "test1.h"??? ????:
????extern char g_str[];
????void fun2() { cout << g_str << endl; }
??????????????????g_str??????????????????????????????????????????????????????????????????????????????????????????test2.cpp?????#include "test1.h"?????test1.h??????????????????????????????????????extern???Σ????????????????????????????????????????????????????????????? ?????? ????????????????????????????????
????6. extern ?? static
????(1) extern ???????????????????????????????????????????.
????(2) static ???????????????????????? ?洢???????????洢???????.
????static ???÷?Χ?????????????? ??extern?е???.??????????????洢???extern??????洢???????extern????????????????extern ???????static ?????????????????????. ???????????static??extern?????“?????”????????extern??static?????????????????????Σ?static???ε????????????????????У????????????????????static??????????????????????????????static?????????????????????????????????????????“???”???????????Ч???????????????????????:
????(1) test1.h:
????#ifndef TEST1H
????#define TEST1H
????static char g_str[] = "123456";
????void fun1();
????#endif
????(2) test1.cpp:
????#include "test1.h"
????void fun1() { cout << g_str << endl; }
????(3) test2.cpp
????#include "test1.h"
????void fun2() { cout << g_str << endl; }
????????????????????????????? ?????test1.obj????????????????????????"123456"?????????????test2.obj????????????????????????????????б????????????????????????????????????????洢?????????????????????????????????????????????????????????????????????????????????? ?????????棬???????????????????????????????????????test1??test2????g_str???????????????????????static???ε?????????????????????飬????????????????????????????????????????????????????????????????????????????????棬???Ч???????????????????????????????????????????????????????????????????"123456"?? λ????????????е???????????????????????????????????????????????????????????????????????????????????????????????????:
????(1) test1.cpp:
????#include "test1.h"
????void fun1()
????{
????g_str[0] = ''a'';
????cout << g_str << endl;
????}
????(2) test2.cpp
????#include "test1.h"
????void fun2() { cout << g_str << endl; }
????(3) void main() {
????fun1(); // a23456
????fun2(); // 123456
????}
?????????????????????????????????????е?g_str????????????????????????????????????????????е????????ò????????д??????????????????????е??????á????????static?????????????????????static????????????????????????ж??????????????????????????????????????????????????????????
????7. extern ??const
????C++??const???ε??????????и?static??????????????????????????????????У?????const??????extern???????????ó?????????????????????????У? ??extern const char g_str[];
??????????????б????????: const char g_str[] = "123456";
?????????const????????????static???????????extern????????????????????extern?????????????const??????????????????????????????????const char* g_str = "123456" ?? const char g_str[] ="123465"??????? ??????const ???ε???char *??????g_str??????g_str??????????????????????????????????????????????????????????? ?????????????char*g_str????const??????????????????????const char* const g_str="123456".
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????