Initializing class using { * this }

Viewed 453

It was suggested by a team member that using an intializer like this:

return Demo{ *this };

was better than:

return Demo(*this);

Assuming a simple class like this:

class Demo {
public:
    int value1;
    Demo(){}
    Demo(Demo& demo) {
        this->value1 = demo.value1;
    }
    Demo Clone() {
        return Demo{ *this };
    }
};

I admit to having not seen the { *this } syntax before, and couldn't find a reference that explained it well enough that I understood how the two options differed. Is there a performance benefit, a syntax choice, or something more?

5 Answers
Related