I
iluvatar
Hi all.
I have written a 3d-vector class (for 3-dimensional space) and I have
overloaded the arihtmetic operators like +, +=, * and so on. Also, the
constructor works with doubles and has default arguments.
In my class, the operator = works for another vector (just copying the
elements), and for a double: in this cases each element of the vector
will be equal to the double. Example:
Vector3D v1;
Vector3D v2 = v1; // v2.x = v1.x, v2.y = v1.y, v2.z = v1.z
double num = 3.0;
Vector3D v2 = num; // v2.x = 3.0, v2.y = 3.0, v2.z = 3.0
Also, I have overloaded the operator *: in the case of tho vector,
like v1*v2, this is just the dot product. But when I writte
v2 = v1*num ; // it means: v2.x = (v1.x)*num, v2.y = (v1.y)*num, v2.z
= (v1.z)*num
My question is: When I have expressions like
v3 = v1*num*num2;
How can I know that I get what I want, i.e., the number num*num2
multiplying the vector v1 and then asigned to v3, and not, for
example, a temporal vector constructed with num, then a dot product
with v1, then multiplication with num2 and at last a new construction
of a vector to assign to v3?
There is some precedence in the constructor and the overloaded
operators?
Thanks in advance.
I have written a 3d-vector class (for 3-dimensional space) and I have
overloaded the arihtmetic operators like +, +=, * and so on. Also, the
constructor works with doubles and has default arguments.
In my class, the operator = works for another vector (just copying the
elements), and for a double: in this cases each element of the vector
will be equal to the double. Example:
Vector3D v1;
Vector3D v2 = v1; // v2.x = v1.x, v2.y = v1.y, v2.z = v1.z
double num = 3.0;
Vector3D v2 = num; // v2.x = 3.0, v2.y = 3.0, v2.z = 3.0
Also, I have overloaded the operator *: in the case of tho vector,
like v1*v2, this is just the dot product. But when I writte
v2 = v1*num ; // it means: v2.x = (v1.x)*num, v2.y = (v1.y)*num, v2.z
= (v1.z)*num
My question is: When I have expressions like
v3 = v1*num*num2;
How can I know that I get what I want, i.e., the number num*num2
multiplying the vector v1 and then asigned to v3, and not, for
example, a temporal vector constructed with num, then a dot product
with v1, then multiplication with num2 and at last a new construction
of a vector to assign to v3?
There is some precedence in the constructor and the overloaded
operators?
Thanks in advance.