C++ has the build-in types such as long long int
, unsigend int
. Type can be combined with qualifiers, such as const
, volatile
and mutable
.
Why is long long int
a datatype? Why is it not named longLongInt
? How does a multi word datatype work? Can I define my own?
Is it possible to define a customized qualifier with respect to a custom datatype?
For example consider a linear algebra vector in 3D. One could define a class LinAlVector, which contains the x-,y-,z-components of the vector.
If I now need to ensure, that this vector is a unit vector (length is equal to 1), I am wondering if I can write
isUnit LinAlVector vec(x,y,z);
where isUnit
is a modifier which is effecting the behaviour of LinAlVector
(e.g. compiler error if a non unit vector is defined).
I know that the OO straight forward way would be to derive a class UnitLinAlVector
from LinAlVector
.