February 16th, 2009, 01:45 AM
what is visibility and scope
What is visibility and scope? what are difference between them?
February 16th, 2009, 03:47 AM
Re: what is visibility and scope
'scope' usually refers to the lifetime of a variable (the time between it getting created and destroyed). 'visibility' refers to whether or not it's accessible. However, it's not quite as simple as that because local variables can hide variables of the same name that were previously visible and in scope. For example:-
myClass(); // c'tor
// Somewhere in your code
myObj.publicInt = 3; // Acceptable - 'publicInt' is public - therefore visible
myObj.privateInt = 3; // 'privateInt' is private - it remains in scope for the duration of 'myObj' but is not visible from outside the object
// Another example
publicInt = 9; // refers to the member variable
int publicInt = 3; // This new declaration hides the member variable temporarily
// Within the scope of these 2 brackets, 'publicInt' refers to the
// local declaration. Member 'publicInt' is temporarily hidden.
x = publicInt; // 'x' will equal 3
x = publicInt; // 'x' will equal 9
"A problem well stated is a problem half solved.” - Charles F. Kettering
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.