Accessing any variable which is belong a function in a class

Hello everyone,

I am trying to access a variable but this variable is in a function of a class. I can access the class, however, i don’t know how can access this variable. Is there any method to manipulate this variable value.

Thanks in advance.

In reply to nrllhclb:

Variables declared in functions/tasks as methods of class have automatic lifetimes. That means they only exist while the method is active and disappear once the method returns. Also remember that functions can be recursive, and tasks can be reentrant, so there can be multiple instances of the same variable at a given point.

My suggestion is seeing if it would make sense to move the variable declaration outside the function to become a class member. My least favorable suggestion is declaring the individual variable with a static lifetime. This is generally considered a bad programming practice because it make your code less reusable.

Agree with Dave here… .This is a local variable inside a function. This implies only the function can change the value of this variable. Also by default this variable is automatic. This implies that the variable is initialized to some default value whenever this function is called and by the end of the function execution, this variable is assigned some new value.

As you want this variable value to be visible outside of the function, you can declare another variable at the class scope (say mirror_var) and update this mirror_var before exiting the function. As long as this mirror_var is “public” you can access the value.

Logie Ramachandran