考虑一下:
class Vec3
{
private:
float n[3];
public:
float& x;
float& y;
float& z;
Vec3(float x_, float y_, float z_) : x(n[0]), y(n[1]), z(n[2])
{
x = x_;
y = y_;
z = z_;
}
}
我可以确定这样做:
Vec3 v(1,2,3);
cout<<reinterpret_cast<float*>(&v)[0]<<"\t";
cout<<reinterpret_cast<float*>(&v)[1]<<"\t";
cout<<reinterpret_cast<float*>(&v)[2]<<"\t";
1 2 3
每个遵循标准的编译器/操作系统都会给我吗?