Is it possible to initializate a class like this?
Quaternion::Quaternion(){ //default without arguments
Quaternion(0.,V3(0.,0.,0.));
}
Quaternion::Quaternion(double s, V3 v){ //with scalar and vector as a argument
coords[0] = s;
coords[1] = v[0];
coords[2] = v[1];
coords[3] = v[2];
}
because this is the output:
QUATERNION TEST
(2.122e-313:-3.22469e-232:2.122e-313:-1.998) //instanciated with Quaternion q;
(4:1:2:3) // instanciated with the Quaternion q(4,1,2,3);
(4:-1:-2:-3) // conjugated of the one above
and first one is not initializated as 0. as it should be… why?
Not in C++03, but the recent version of C++ allows delegating constructors:
In a delegating constructor, the initializer list must have precisely one element, which is another constructor (and obviously there mustn’t be any circular references).
Pre-C++11 you don’t really get around copy/pasting if you want to actually initialize your class members directly in the constructor. Maybe you would like to use default arguments, though? Some people object to those….