什么是静态常量和const区别? [英] What is the difference between static const and const?

查看:110
本文介绍了什么是静态常量和const区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  常量VS静态常量

什么是静态常量常量之间的区别?
例如:

What is the difference between static const and const? For example:

static const int a=5;
const int i=5;

他们之间有什么区别吗?
当你使用一个比其他?

Is there any difference between them? When would you use one over the other?

推荐答案

不同的是联动

// At file scope
static const int a=5;  // internal linkage
const int i=5;         // external linkage

如果在 I 对象并不定义它的翻译单元之外使用,你应该用静态符。

If the i object is not used outside the translation unit where it is defined, you should declare it with the static specifier.

这使编译器(潜在的)进行进一步的优化,并通知该对象不是它的翻译单位以外使用的阅读器。

This enables the compiler to (potentially) perform further optimizations and informs the reader that the object is not used outside its translation unit.

这篇关于什么是静态常量和const区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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