why the following code cannot compile?

why the following code cannot compile?

Wei Pan的头像

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 帖子 / 0 new
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项.
AmandaS (Intel)的头像

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

登陆并发表评论。