C++语言开发示例:06. 外部变量
external.cpp
#include <iostream>
using namespace std;
double warming = 0.3;
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";
}support.cpp
#include <iostream>
extern double warming;
void update(double dt);
void local();
using std::cout;
void update(double dt)
{
extern double warming;
warming += dt;
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;
cout << " degrees.\n";
} 最后更新于1年前
本文由人工编写,AI优化,转载请注明原文地址: C++语言开发示例:06. 外部变量
推荐阅读
评论 (0)
发表评论
昵称:加载中...
暂无评论,快来发表第一条评论吧!