Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Refactoring: Move initializer list
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

str
Junior Member

12 Posts

Posted - Oct 07 2020 :  09:38:18 AM  Show Profile  Reply with Quote
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

feline
Whole Tomato Software

United Kingdom
16947 Posts

Posted - Oct 07 2020 :  10:52:09 AM  Show Profile  Reply with Quote
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?

zen is the art of being at one with the two'ness
Go to Top of Page

str
Junior Member

12 Posts

Posted - Oct 07 2020 :  11:33:10 AM  Show Profile  Reply with Quote
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;

Edited by - str on Oct 07 2020 11:33:43 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16947 Posts

Posted - Oct 07 2020 :  12:12:59 PM  Show Profile  Reply with Quote
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

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2019 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000