Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Refactoring: Initialize member

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
khb Posted - Jul 04 2006 : 08:35:37 AM
When I add members to a class I normally need to initialize them in the Constructor. I would be nice if this would be possible from the refactoring menu. E.g., numeric values are initialized with 0 or 0.0, respectively. Pointers should be set to NULL.

Regards,
Marcus.
4   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Jul 06 2006 : 5:34:20 PM
purely as a discussion, how well, or how badly, does the concept of "initialize in constructor" work as a refactoring for a member variable?

ideally i should be able to select 6 lines of code in my C++ header, which define 8 member variables, and have all of them added to all constructors, initialized with default values.

in reality it might start as one at a time. but then you have to consider overloaded constructors, and possibly copy constructors. plus i recall from Effective C++ that you should initialize the member variables in the order that they are defined, which is yet another complication.

any one got any brilliant thoughts on this one?

the more i use refactoring the more i rely on it, and the more i want it to do but there are limits.
khb Posted - Jul 05 2006 : 02:08:37 AM
Ok, I was only considering the most simple cases (e.g., basic variables) which appear most often to me. I see, it's very hard to make a general solution out of it. Anyway, thanks for the discussion!

Regards,
Marcus.
feline Posted - Jul 04 2006 : 6:18:05 PM
member variables that already have their own default constructors, like strings?

personally i do like the idea, but like bugfix i wonder how feasible it is. plus what about things like copy constructors?

*considers*

i think the real danger lies in cases like:

the class contains an int, and the constructor is setting this to 4
you then ask VA to do something with the member variables, and suddenly further down the constructor the int is set to zero by VA, thus breaking the code.

if you manually do this then that is one thing, at least you might notice the problem, but if VA is doing it, it increases the odds of auto generating bugs.
bugfix Posted - Jul 04 2006 : 11:31:51 AM
No offense, but I think this is almost impossible to implement properly.
Initialize in ctor's initializer list or function body?
What happens when you have more than one ctor or even worse no ctor yet?
Whats w/ static or const members?

Guess there is even more problems:)

-bugfix

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000