Inquiry about class variable declarations in C++

前端 未结 6 1173
悲&欢浪女
悲&欢浪女 2021-01-19 00:43

I have a class to represent a 3D vector of floats:

class Vector3D
{
    public:

    float x, y, z;
    float * const data;

    Vector3D() : x(0.0), y(0.0),         


        
6条回答
  •  情歌与酒
    2021-01-19 01:29

    Do something like this:

    float data[3];
    float& x, y, z;
    
        Vector3D() : x(data[0]), y (data[1]), z(data[2]) { data [0] = data [1] = data [2] = 0;}
    

提交回复
热议问题