Author |
Topic |
|
khb
Tomato Guru
Germany
337 Posts |
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. |
|
bugfix
Tomato Guru
Germany
324 Posts |
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 |
http://www.mf-sd.de |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
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. |
zen is the art of being at one with the two'ness |
|
|
khb
Tomato Guru
Germany
337 Posts |
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
Whole Tomato Software
United Kingdom
19021 Posts |
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. |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|