variable declaration dought
-
Hi all I am having a C++ class and in that some functions are also there.One variable i want to use in a function only.So i can declare it inside that function or as a member variable. Variables declared in a function will be saved on the stack but what about member variables. Which way should be more efficient. Can anybody help me to show some good articles in good programming practices. Thanks and regards Deepu
-
Hi all I am having a C++ class and in that some functions are also there.One variable i want to use in a function only.So i can declare it inside that function or as a member variable. Variables declared in a function will be saved on the stack but what about member variables. Which way should be more efficient. Can anybody help me to show some good articles in good programming practices. Thanks and regards Deepu
Where member variables are stored will depend upon how the class is instantiated. If an object of the class is created on the stack, the member variables will also reside on the stack. If the object is created on the heap, the member variables will also reside on the heap. If a variable is used only within a function, you should declare it within that function itself. And if you want the value retained across function calls, then declare it static.
«_Superman_» I love work. It gives me something to do between weekends.
-
Where member variables are stored will depend upon how the class is instantiated. If an object of the class is created on the stack, the member variables will also reside on the stack. If the object is created on the heap, the member variables will also reside on the heap. If a variable is used only within a function, you should declare it within that function itself. And if you want the value retained across function calls, then declare it static.
«_Superman_» I love work. It gives me something to do between weekends.
Thanks..