通过本文主要向大家介绍了c++ 函数声明 const,c++ const,c++ const用法,c++ const函数,c++ const用法总结等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
当在C源代码文件中将变量声明为const时,可以通过以下方式实现:
const int i = 2;</div>
然后,可以在另一个模块中使用此变量,如下表示:
extern const int i;</div>
但若要获取与 C++ 中相同的行为,则必须将 const 变量声明为:
extern const int i = 2;</div>
如果希望在 C++ 源代码文件声明用于 C 源代码文件的 extern 变量,请使用:
extern "C" const int x = 10;</div>
以防止 C++ 编译器进行名称重整。
</div>