Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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?

like image 487
Tony R Avatar asked Nov 28 '22 10:11

Tony R


1 Answers

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.

like image 63
sharptooth Avatar answered Dec 04 '22 14:12

sharptooth