Nader Elshehabi wrote:
What's the difference between declaring a variable as a class member or as a static in a function in a class??
Actually I meant that a class might not be necessary. And if it is an existing class that is being used then it could be difficult to change the design in a manner as to provide the var at object creation time. This function can be put outside a class or if inside it wont require change to construction code. One difference is that the member var will be unique to each object but as static in a function in a class it will have to be shared.
Nader Elshehabi wrote:
You can change temp3 to whatever you want after the call.
Right! I was tempted to return a val by ref but realized that the guy had already tried to use pointers to manipulate a const var. So this seems safer. Also, even a public class member can be assigned to a temp and anything can be done.
Nader Elshehabi wrote:
scenario where we should use this approach
as in the differences above
Nader Elshehabi wrote:
I hope you don't mean reverse engineering?
Not at all :). Only in this case even if someone uses a pointer to the returned val they will not be changing the actual var storing the const. Actually, only the first line was for you :) Yes your approach is excellent if there is an existing class which is being instantiated after the value is known. I should have thought about that. Thanks for the reply!
---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.