Home > Back-end >  Data of different name used in the union of C ⒖ believers 膯 栴}?
Data of different name used in the union of C ⒖ believers 膯 栴}?

Time:09-23

Hello, everyone I meet a problem in the past we had some graphic design in mathematics classes, including through the union to implement data vision

The class CMatrix4FLOAT {
Public:
The union {
Struct {float m_Buffer [16]. };
Struct {float _M00, _M10 _M20, _M30,
_M01 _M11, _M21 _M31,
_M02 _M12, _M22 _M32,
_M03 _M13, _M23 _M33; };
}
.
.
};

Or

The class CVectorReference4FLOAT {
Public:
The union {
Struct {float & amp; M_x, & amp; M_y, & amp; M_z, & amp; M_w. };
Struct {float & amp; M_s, & amp; M_t, & amp; M_p, & amp; M_q; };
Struct {float & amp; M_r, & amp; M_g, & amp; M_b, & amp; M_a; };
}
.
.
};

Question after VS2015 C11 does not allow the use of reference in the union, do you have other method to implement data have different name? Or I can only be compelled to use indicators?

CodePudding user response:

This, you can use the alias in the class object level ah, don't in class member alias, direct object alias, be a problem? A pointer to a different name, alias is what you said is what you said,

CodePudding user response:

Do you want us to use anonymous consortium and add a name to a consortium, (structure)

CodePudding user response:

reference 1st floor zjq9931 response:
this, you can use the alias in the class object level ah, don't in class members alias, alias object directly, be a problem? A pointer to a different name, alias is what you said is what you said,


Because this is the situation with computer graphics design objects CVectorReference4FLOAT can be said to be the kind of container
According to the using situation of the same position will appear different meanings

A float Buffer [4].
CVectorReference4FLOAT P0 (Buffer);
CVectorReference4FLOAT Color (Buffer);
CVectorReference4FLOAT Coordinate (Buffer);

P0. Set (f 5.0 f, f 3.0, 1.0, 1.0 f);
P0. M_x=5.0 f; P0. M_y=5.0 f; P0. M_z=5.0 f;

Color. The Set (0.3 f, f, 0.5 0.2 f, 1.0 f);
Color. M_r=1.0; Color. M_g=1.0; Color. M_b=1.0;

This very good read meaning is very clear, it is designed with GLSL


CodePudding user response:

reference YanShiHong reply: 3/f
because this is the situation with computer graphics design objects CVectorReference4FLOAT can be said to be the kind of container
According to the using situation of the same position will appear different meanings

A float Buffer [4].
CVectorReference4FLOAT P0 (Buffer);
CVectorReference4FLOAT Color (Buffer);
CVectorReference4FLOAT Coordinate (Buffer);

P0. Set (f 5.0 f, f 3.0, 1.0, 1.0 f);
P0. M_x=5.0 f; P0. M_y=5.0 f; P0. M_z=5.0 f;

Color. The Set (0.3 f, f, 0.5 0.2 f, 1.0 f);
Color. M_r=1.0; Color. M_g=1.0; Color. M_b=1.0;

This very good read meaning is very clear, it is designed with GLSL


Members of the group (or structure) if not & amp; Reference, seems to add a constructor can, if use & amp; References to a consortium (or structure) with a pointer or also want to add a constructor,
For example,
 
The class SV16 {
Public:
The union {
Struct {float m_Buffer [16]. };
Struct {float _M00, _M10 _M20, _M30,
_M01 _M11, _M21 _M31,
_M02 _M12, _M22 _M32,
_M03 _M13, _M23 _M33; };
};
SV16 () {}//add a constructor
SV16 (float buff [16]) {memcpy (m_Buffer, buff, 16); }
};

Int main () {
Float buff1 [16]=,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 {1};
SV16 SV16 (buff1);
Printf (" % f \ n ", sv16 _M00);
return 0;
}

CodePudding user response:

reference YanShiHong reply: 3/f
Quote: refer to 1st floor zjq9931 response:

This, you can use the alias in the class object level ah, don't in class member alias, direct object alias, be a problem? A pointer to a different name, alias is what you said is what you said,


Because this is the situation with computer graphics design objects CVectorReference4FLOAT can be said to be the kind of container
According to the using situation of the same position will appear different meanings

A float Buffer [4].
CVectorReference4FLOAT P0 (Buffer);
CVectorReference4FLOAT Color (Buffer);
CVectorReference4FLOAT Coordinate (Buffer);

P0. Set (f 5.0 f, f 3.0, 1.0, 1.0 f);
P0. M_x=5.0 f; P0. M_y=5.0 f; P0. M_z=5.0 f;

Color. The Set (0.3 f, f, 0.5 0.2 f, 1.0 f);
Color. M_r=1.0; Color. M_g=1.0; Color. M_b=1.0;

This very good read meaning is very clear, it is designed with GLSL



With object references can achieve the purpose of you!

A float Buffer [4].
CVectorReference4FLOAT P0 (Buffer);//class has 16 float here only 4, you can normal initialization?
CVectorReference4FLOAT & amp; Color=P0;
CVectorReference4FLOAT & amp; Coordinate=P0;

P0. Set (f 5.0 f, f 3.0, 1.0, 1.0 f);
P0. M_x=5.0 f; P0. M_y=5.0 f; P0. M_z=5.0 f;

Color. The Set (0.3 f, f, 0.5 0.2 f, 1.0 f);
Color. M_r=1.0; Color. M_g=1.0; Color. M_b=1.0;

CodePudding user response:

The
reference 4 floor qybao reply:
members of the consortium (or structure) if not & amp; Reference, seems to add a constructor can, if use & amp; References to a consortium (or structure) with a pointer or also want to add a constructor,
For example,
 
The class SV16 {
Public:
The union {
Struct {float m_Buffer [16]. };
Struct {float _M00, _M10 _M20, _M30,
_M01 _M11, _M21 _M31,
_M02 _M12, _M22 _M32,
_M03 _M13, _M23 _M33; };
};
SV16 () {}//add a constructor
SV16 (float buff [16]) {memcpy (m_Buffer, buff, 16); }
};

Int main () {
Float buff1 [16]=,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 {1};
SV16 SV16 (buff1);
Printf (" % f \ n ", sv16 _M00);
return 0;
}


Yes matrix currently don't have what problem, we has achieved, in the past in VS2008 reference part use prefabricated type

 
CVectorReference4FLOAT: : CVectorReference4FLOAT (float & amp; Value0, float & amp; Value1, float & amp; Value2, float & amp; Value3) :
M_x (Value0), m_y (Value1), m_z (Value2), m_w (Value3),
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related