C++??extern????????
???????????? ???????[ 2015/8/21 13:45:42 ] ??????????????????? ????????
???????У?????C???????????????
????extern "C"
????{
????//extern int i;
????//extern void func();
????#include "devVar.h"
????}
????д??????¥???????????????????????????????C++????C??????????????C????C++??д????????
????¥??????????????
????devVar.cpp???????
????#include <stdio.h>
????int i = 1;
????void func()
????{
????printf("%d"??i++);
????}
????extern.c????????
????#include <stdio.h>
????extern int i;
????extern void func();
????int main(void)
????{
????int x = 0;
????for (;x < 10; x++)
????{
????func();
????}
????}
????????????????????????????????????????????????
????1>extern.obj : error LNK2019: unresolved external symbol _func referenced in function _main?????.c?????extern void func()??????C???????????????_func????devVar.cpp???????C++????????????????XX·??_func(????¥??????????)?????????????????????????????????????
?????????devVar.cpp?У????????extern "C"??????????cpp??????й???????????C??????????????devVar.cpp????????????
????#include <stdio.h>
????int i = 1;
????extern "C" void func()
????{
????printf("%d"??i++);
????}
???????????????????extern "C"???????????????C?????????.cpp????е??????????C++?????д??????
????devVar.cpp???????淽?д???????????
????#include "stdafx.h"
????#include <iostream>
????using namespace std;
????int i = 1;
????extern "C" void func()
????{
????cout << "i = " << i++ << endl;
????chapter 2 . extern??????????
????extern?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????ж??壬??????????????
// extern.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
extern int i;
extern void func();
int _tmain(int argc?? _TCHAR* argv[])//typedef wchar_t _TCHAR;#define _tmain wmain
{
i = 0;
func();
return 0;
}
int i;
void func()
{
i++;
cout << "i = " << i << endl;
}
????????????б???i?????func??????β???壬?????????????extern????????????????????????????塣extern int i????????extern i??????????????????????????????????????????????i??????????????????????ж?i = 0?????????????????????
?????????????????????е?????????????????extern???????????
???????????????????????е??????????????????????????????
????????????????????????????????????????????ж??????????
???????????extern???????????????????????.cpp????.c????ж??????????
???????????????????
????devVar.cpp?????ж??壺
????#include "stdafx.h"
????int i;
????extern.cpp??
// extern.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
extern int i;
extern void func();
int _tmain(int argc?? _TCHAR* argv[])//typedef wchar_t _TCHAR;#define _tmain wmain
{
i = 0;
func();
return 0;
}
void func()
{
i++;
cout << "i = " << i << endl;
}
????????????????????i = 1?????????extern???????????????cpp????ж??????????????
????#include <filensme> --- ??filename????е?????????μ?????С?
????deVar.h????д????
????#include <stdio.h>
????int i = 1;
????void func()
????{
????printf("%d"??i++);
????}
????????func?????????i??????????
????extern.cpp??????????
????#include "stdafx.h"
????#include <stdio.h>
????#include <iostream>
????using namespace std;
????#include "devVar.h"
????//extern int i;
????//extern void func();
????int main(void)
????{
????for (int x = 0;x < 10; x++)
????{
????func();
????}
????}
???????????1??2??3??4??5??6??7??8??9??10??????#include <filname.h> ???????????????????е?????????????????????????
// extern.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
extern int i;
extern int func(int);//????extern????????????????????cpp?????
int _tmain(int argc?? _TCHAR* argv[])//typedef wchar_t _TCHAR;#define _tmain wmain
{
i = 100;
func(i);
return 0;
}
????devVar.cpp????????????
#include "stdafx.h"
#include <iostream>
using namespace std;
int i;
int func(int a)
{
i = a;
cout << "i = " << i << endl;
return 0;
}
????????????????????i= 100??
??????????extern????????cpp????ж???????????????????
???????????????????cpp??????????????????????????????????????????????У?????????????????????????????????????????????????????????????????????????????????????????????????к???????????????????????????????????κ?????ж???????????????????????????????????????????????????????????????????
????// extern.cpp : Defines the entry point for the console application.
????//
????#include "stdafx.h"
????#include <iostream>
????using namespace std;
????int i;
????extern int func(int);//????extern?????????????????cpp?????
????int _tmain(int argc?? _TCHAR* argv[])//typedef wchar_t _TCHAR;#define _tmain wmain
????{
????i = 100;
????func(i);
????return 0;
????}
????devVar.cpp????У????????
????#include "stdafx.h"
????#include <iostream>
????using namespace std;
????int i;
????int func(int a)
????{
????i = a;
????cout << "i = " << i << endl;
????return 0;
????}
????????compile?κ????cpp?????????????? ??????????????????????????
????1>LINK : D:vctestexternDebugextern.exe not found or not built by the last incremental link; performing full link
????1>devVar.obj : error LNK2005: "int i" (?i@@3HA) already defined in extern.obj
????1>D:vctestexternDebugextern.exe : fatal error LNK1169: one or more multiply defined symbols found
??????????????.cpp????ж?????????????i????????????????
????PS:??????.h????е????????????????extern???????????????#include <filename>???????????.h????е??????????cpp????У???????????????????.h????ж?????????????????????????????cpp??????????.h???????????????????extern??????.h????ж????????????????????????extern????????????????.cpp????????????????????????????????
???????????????????????漰???????????????????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 ??????