How exactly does initialization list make code run faster in C++?

52 Views Asked by At

I have a simple class

class ImaginaryNumber {
    private:
    int _real;
    int _imaginary;
    public:
    ImaginaryNumber(int real, int imaginary) {
        _real = real;
        _imaginary = imaginary;
    }
};

int main() {
    ImaginaryNumber i = ImaginaryNumber(1, 2);
    return 0;
}

And the assembler code is the exact same thing when I change the constructor to an initialization list (compiled with g++ -S main.cpp). So in what case does it make a difference?

0

There are 0 best solutions below