What is the scope of variables declared in a class constructor?(类构造函数中声明的变量的范围是什么?)
问题描述
我很好奇,在类构造函数中声明的不是该类的数据成员的变量的范围是什么?
I was curious, what is the scope of variables declared inside a class constructor which are not data members of that class?
例如,如果一个构造函数需要一个迭代 int i,这个变量会在构造函数完成后被销毁,还是对程序来说是全局的?
For example, if a constructor needs an iterating int i, will this variable be destroyed after the constructor finishes, or is it then global for the program?
推荐答案
在这个意义上,构造函数就像任何其他函数一样 - 在内部声明的任何变量都有通常的作用域限制,一旦构造函数被破坏,它们肯定会超出作用域并被销毁完成.
In this sense a constructor is like any other function - any variable declared inside has usual scope limitations and they all surely go out of scope and get destroyed once constructor is finished.
这篇关于类构造函数中声明的变量的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:类构造函数中声明的变量的范围是什么?
基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
