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
 C++ constructors: default the member variables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

OnlineCop
New Member

USA
2 Posts

Posted - Jun 27 2017 :  12:35:33 PM  Show Profile  Reply with Quote
Given a new class:

    class MyClass
    {
    public:
    	MyClass();
    protected:
    	int a;
    	char* b;
    	AnotherClass c;
        const short d;
    };
I would love to right-click the MyClass() constructor and have an option to "Create Implementation with member variables set to defaults". That might look like either:

    MyClass::MyClass()
    	: a(0)
    	, b(nullptr)
    	, c(AnotherClass())
        , d(0)
    {}
or

    MyClass::MyClass()
    	: d(0)
    {
    	a = 0;
    	b = nullptr;
    	c = AnotherClass();
    }

Or whatever each type's default would be. Granted, const variables need to be initialized in constructors, and there is always the worry of weird edge cases, but just being able to throw all these member variables into a constructor would make it easier to remember to initialize everything properly (ever forget to set or null a pointer that you declared somewhere?).

feline
Whole Tomato Software

United Kingdom
18751 Posts

Posted - Jun 27 2017 :  2:09:24 PM  Show Profile  Reply with Quote
We are considering adding a command to do this:

case=10622

One of the questions is what to do with any complex type. We may have to have a comment saying a value is required in some cases, where there is no obvious default value.

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:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000