全局变量V.S.C ++中的文件变量 [英] global variable V.S. file variable in C++

查看:54
本文介绍了全局变量V.S.C ++中的文件变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中的全局变量和文件变量有什么区别?

what is the difference between global variable and file variable in C++?

谢谢!

推荐答案

在C和C ++中,可以通过使用声明前面的static关键字,使全局变量仅可从声明了该文件的文件访问.可以通过编译到程序中的任何C或C ++文件访问不使用static关键字的全局变量.

In C and C++ you can make a global variable only accessible from the file in which it's declared by using the static keyword in front of the declaration. Globals that don't use the static keyword are accessible from any C or C++ file compiled into the program.

在C ++中不推荐使用静态全局方法,而使用匿名名称空间.放置在匿名名称空间中的所有声明也只能从该文件中访问.

The static global method is deprecated in C++ in favor of anonymous namespaces. Any declarations placed inside an anonymous namespace are also only accessible from within that file.

这篇关于全局变量V.S.C ++中的文件变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆