M
Marcin Kalicinski
Hi,
I found out that default constructor of std::complex class initializes the
value to (0,0). I wonder why is it so?
Because of this, the code below is about two times slower than it could be
if the default constructor left the values uninitialized.
void f()
{
using namespace std;
complex c[100];
for (int i = 0; i < 100; ++i) c = complex(1, 0);
}
Values of built in types work perfectly without zero initialization, so why
make complex different and cause additional learning trouble?
Best regards,
Marcin
I found out that default constructor of std::complex class initializes the
value to (0,0). I wonder why is it so?
Because of this, the code below is about two times slower than it could be
if the default constructor left the values uninitialized.
void f()
{
using namespace std;
complex c[100];
for (int i = 0; i < 100; ++i) c = complex(1, 0);
}
Values of built in types work perfectly without zero initialization, so why
make complex different and cause additional learning trouble?
Best regards,
Marcin