Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: constant variable at run time Pin
Ahmed Ismail Mohamed2-Sep-06 12:03
Ahmed Ismail Mohamed2-Sep-06 12:03 
GeneralRe: constant variable at run time Pin
Waldermort2-Sep-06 12:15
Waldermort2-Sep-06 12:15 
AnswerRe: constant variable at run time [modified] Pin
Nader Elshehabi2-Sep-06 13:48
Nader Elshehabi2-Sep-06 13:48 
GeneralRe: constant variable at run time Pin
Bram van Kampen2-Sep-06 14:46
Bram van Kampen2-Sep-06 14:46 
AnswerRe: constant variable at run time Pin
Nader Elshehabi2-Sep-06 19:15
Nader Elshehabi2-Sep-06 19:15 
GeneralRe: constant variable at run time [modified] Pin
MayankT2-Sep-06 23:41
MayankT2-Sep-06 23:41 
GeneralRe: constant variable at run time Pin
Nader Elshehabi3-Sep-06 1:07
Nader Elshehabi3-Sep-06 1:07 
GeneralRe: constant variable at run time Pin
MayankT3-Sep-06 15:23
MayankT3-Sep-06 15:23 
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 Smile | :) . 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 Smile | :) 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.

GeneralRe: constant variable at run time Pin
Nader Elshehabi3-Sep-06 17:48
Nader Elshehabi3-Sep-06 17:48 
Questiontext buffer conversion Pin
FredrickNorge2-Sep-06 10:12
FredrickNorge2-Sep-06 10:12 
AnswerRe: text buffer conversion Pin
Waldermort2-Sep-06 11:27
Waldermort2-Sep-06 11:27 
GeneralRe: text buffer conversion Pin
FredrickNorge2-Sep-06 12:06
FredrickNorge2-Sep-06 12:06 
GeneralRe: text buffer conversion Pin
Waldermort2-Sep-06 12:13
Waldermort2-Sep-06 12:13 
GeneralRe: text buffer conversion Pin
FredrickNorge2-Sep-06 12:16
FredrickNorge2-Sep-06 12:16 
GeneralRe: text buffer conversion Pin
Waldermort2-Sep-06 12:27
Waldermort2-Sep-06 12:27 
GeneralRe: text buffer conversion Pin
FredrickNorge2-Sep-06 12:33
FredrickNorge2-Sep-06 12:33 
GeneralRe: text buffer conversion Pin
FredrickNorge2-Sep-06 14:11
FredrickNorge2-Sep-06 14:11 
GeneralRe: text buffer conversion Pin
Waldermort2-Sep-06 19:36
Waldermort2-Sep-06 19:36 
QuestionEdit Box multiple lines Pin
Oliver1232-Sep-06 8:03
Oliver1232-Sep-06 8:03 
AnswerRe: Edit Box multiple lines Pin
Oliver1232-Sep-06 8:06
Oliver1232-Sep-06 8:06 
GeneralRe: Edit Box multiple lines Pin
James Brown2-Sep-06 8:09
James Brown2-Sep-06 8:09 
GeneralRe: Edit Box multiple lines Pin
Oliver1232-Sep-06 11:39
Oliver1232-Sep-06 11:39 
QuestionHide System Menu Close (X) button for MessageBox Pin
Pradeep.Reddy2-Sep-06 3:47
Pradeep.Reddy2-Sep-06 3:47 
AnswerRe: Hide System Menu Close (X) button for MessageBox Pin
Jun Du2-Sep-06 6:37
Jun Du2-Sep-06 6:37 
AnswerRe: Hide System Menu Close (X) button for MessageBox Pin
Cristian Amarie2-Sep-06 7:01
Cristian Amarie2-Sep-06 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.