Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 C++ constructors: default the member variables

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
OnlineCop Posted - Jun 27 2017 : 12:35:33 PM
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?).
1   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Jun 27 2017 : 2:09:24 PM
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.

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