求大神指導!!!
第一個檔案
// external.cpp -- external variables
// compile with support.cpp
#include <iostream>
using namespace std;
// external variable
double warming = 0.3; // warming defined
// function prototypes
void update(double dt);
void local();
int main()
{
cout << "Global warming is " << warming << " degrees.\n";
update(0.1);
cout << "Global warming is " << warming << " degrees.\n";
local();
cout << "Global warming is " << warming << " degrees.\n";
return 0;
}
第二個檔案
// support.cpp -- use external variable
// compile with external.cpp
#include <iostream>
extern double warming; // use warming form another file
// function prototypes
void update(double dt);
void local();
using std::cout;
void update(double dt)
{
extern double warming; // optional redeclaration
warming += dt; // uses global warming
cout << "Updating global warming to " << warming;
cout << " degrees.\n";
}
void local()
{
double warming = 0.8;
cout << "Local warming = " << warming << " degrees.\n";
cout << "But global warming = " << ::warming << " degrees.\n";
}
編譯不通過,出現這個問題!!!

仍要除錯后

C:\Users\wulc1\AppData\Local\Temp\cczMrAQE.o: In function `main':
f:/git/9.5_external.cpp:14: undefined reference to `update(double)'
f:/git/9.5_external.cpp:16: undefined reference to `local()'
collect2.exe: error: ld returned 1 exit status
求大神指導一下!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/123360.html
標籤:C++ 語言
上一篇:請問一下這個雙鏈表的洗掉問題,是指標指到了沒有初始化的地方嗎,該怎么修改呢,謝謝
下一篇:編程題求助
