If I have a class as follows:
class MyData
{
public:
MyData( const AnotherObject& obj );
int getA() { return A; }
int getB() { return B; }
private:
int A : 16;
int B : 16;
}
Will the fact that I have specified the variables A and B to take up only 16 bits be rendered pointless by the getters? If I pass an instance of this class around, and other objects want access to A and B but I want to preserve the sizing that I have specified, will I lose that because getA() and getB() will return 32-bit copies?
Would I be better off making A and B public and accessing them directly as required? Will this preserve the sizing? Or should I return references to them from the getters?
The getters will convert the 16 bit value to the size of the
inton the system value and will return 32-bit copies (if the size is 32 bits).What is it that you’re trying to achieve? Why not use
int16_tfrom<cstdint>?