why the following code cannot compile?

why the following code cannot compile?

Just read through the guide. The following code is from the guide page 44.

The error message is

/usr/include/c++/4.2/complex:532: error: invalid initialization of non-const reference of type 'arbb_2::scalar&' from a temporary of type 'arbb_2::scalar'

Am I doing something wrong?

Thanks

======================================

#include
#include
#include

int main() {
std::complex z(1.0, 2.0);
z = z * z;

// cannot compile, initialization errors
arbb::f32 r = std::real(z);
arbb::f32 i = std::imag(z);
std::cout << "z = " << arbb::value << " + "
<< arbb::value(i) << " * I " << std::endl;

// this part is fine
// arbb::f32 mag = std::abs(z);
// std::cout << "mag(z) = " << arbb::value(mag) << std::endl;

return 0;
}

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Hi,No you are not doing anything wrong.This code builds and runs on Windows* using Visual Studio and Intel C++ Compiler.It will not build and run on Linux* using GCC and Intel C++ Compiler. On Linux you can use this workaround.

Change this:

arbb::f32 r =
std::real(z);

arbb::f32 i =
std::imag(z);

to this:

arbb::f32 r =
z.real();

arbb::f32 i =
z.imag();

Thanks for reporting this issue.Regards,--Amanda

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen