{Apologies for any incorrect language and syntax when describing this, i'm a complete novice at c++!} I want to modify a method which i've defined as a vector, with another method so I can easily modify the vector components but i'm having some trouble. This is my vector method:
1 2 3 4 5 6 7 8 9
|
// Cartesian constructor
threevector(double x, double y, double z)
{
xcoord = x;
ycoord = y;
zcoord = z;
cartesian = true;
}
|
I have already defined xcoord, yco...etc in the private section of my class, and the cartesian = true is just there because I used spherical polar later and wanted to differentiate in other methods.
In my main I want to be able to modify some generic threevector (call it v1, with coordinates (1, 2, 3)) with a new method, setx(double ...). Here is my current code for this modifier:
1 2 3 4 5
|
// Modifier method for cartesian coordinates
void setx(double x)
{
x = xcoord;
}
|
I'm worried about this code fragment writing the current xcoord value (xcoord of v1 = 1) in the memory location that x (x = 2.0 in the case below) is stored and not the other way around, where the latter is the clearly desired result. Furthermore, an error which I dont understand was returned when I tried to call this method in my main with the following code:
|
cout << v1.setx(2.0) << endl;
|
The error returned was as follows:
"Invalid operands to binary expression ('ostream'(aka 'basic_ostream<char>') and 'void')
Any ideas how to fix this?
Thanks, any help appreciated!