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

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
str Posted - Oct 07 2020 : 09:38:18 AM
Hi,
it would be nice, if it is possible to move entries from class initializer list to declaration.

class C
{
int a;
// int a = 0; result
};

C::C() : a(0) {}

Moving this a = 0 to declaration would be a great job for VAssist.
Moving it manually for many entries is very error prone.

Best regards
Steffen
5   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Oct 26 2020 : 07:09:41 AM
Moving the initializer from the constructor body to the class declaration makes sense, I have added this to the feature request.

As for Code Inspection, we are looking into running this across all of the files in the solution:

case=104537

we do want to make sure that we have a solid and reliable code inspection feature first though, so hopefully get it out of beta soon
Wolfram_Kuss Posted - Oct 25 2020 : 09:00:16 AM
That would be a very nice feature.

Actually, there are three ways to initialize a member during creation of the object:
1. An assignment "member = value;" in the constructor
2. The (member) initializer lists thre orignal poster speaks about
3. The initialization inside the class declaration.

I think it is general consensus (and I agree with it), that 3 is better than 2 and 2 is better than 1. So it would be nice, if the constructor begins with one or several "member = value;" assignments to also refactor these to use the third option.

That and doing code inspection on all files in a project would be my top wishes.
feline Posted - Oct 07 2020 : 12:12:59 PM
I had no idea this was valid C++ syntax, thank you for explaining. This is a lot clearer and makes the code more readable, making it a sensible refactoring to add. I have put in a feature request for this:

case=142935

Always something new to learn
str Posted - Oct 07 2020 : 11:33:10 AM
No,
I mean exactly this. Since C++11 you are allowed t initialiize values in the class declaration (https://en.cppreference.com/w/cpp/language/data_members)
Original:
class C
{
C::C() : a(0) {}
int a;
};


After refactor:
class C
{
C() = default;
int a = 0;
};

or
class C
{
C();
int a = 0;
};

C::C() = default;
feline Posted - Oct 07 2020 : 10:52:09 AM
I am not sure what you are asking for. You cannot specify the value of a class member variable inside the class declaration.

You can initialize the member variable inside the constructor body, if that is what you are talking about.

Or are you trying to get VA to create the declaration for a new class member variable, based on it being initialized at the constructor?

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