类构造函数中声明的变量的范围是什么? [英] What is the scope of variables declared in a class constructor?

查看:22
本文介绍了类构造函数中声明的变量的范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,在类构造函数中声明的不是该类的数据成员的变量的范围是什么?

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.

这篇关于类构造函数中声明的变量的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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