H
huili80
Like in the following. Though it gives the expected result with
gcc4.0, is it really safe to do that?
What if it's not double but some non-POD type?
-----------------------------------------
#include <complex>
#include <iostream>
#include <iterator>
int main()
{
using namespace std;
const size_t n = 5;
complex<double> ca[n];
double* dp = reinterpret_cast<double*>(ca);
for (size_t i = 0; i < 2*n; ++i )
dp = i;
copy(&ca[0],&ca[n],ostream_iterator<complex<double> >(cout,", "));
cout << endl;
return 0;
}
gcc4.0, is it really safe to do that?
What if it's not double but some non-POD type?
-----------------------------------------
#include <complex>
#include <iostream>
#include <iterator>
int main()
{
using namespace std;
const size_t n = 5;
complex<double> ca[n];
double* dp = reinterpret_cast<double*>(ca);
for (size_t i = 0; i < 2*n; ++i )
dp = i;
copy(&ca[0],&ca[n],ostream_iterator<complex<double> >(cout,", "));
cout << endl;
return 0;
}