Variable Declaration & Initialization :: C++

Status
You're currently viewing only Tristram's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

Tristram

Ars Scholae Palatinae
1,428
Subscriptor
Scott Meyers had a point in one of his books that said (I'm paraphrasing) 'Prefer to defer declaration unitl you have a useful value.' His main point was that doing otherwise may lead to Default Constructor and Assignment call, intread of having only one constructor call. Not a hard and fast rule, but, like using ++i; instead of i++; it can make a difference in the lifetime cost of the program.

A side benefit is that it improves logical locality of reference, which may help uderstanding the code.

I prefer locating them as close as I can to use, but in many ways this is personal preference.
 
Status
You're currently viewing only Tristram's posts. Click here to go back to viewing the entire thread.
Not open for further replies.