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.
这篇关于类构造函数中声明的变量的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:类构造函数中声明的变量的范围是什么?


- 近似搜索的工作原理 2021-01-01
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 静态初始化顺序失败 2022-01-01