Hello, I'm VERY new to the C++ language. I'd also like to note that I only have minimal experience with one other language, GML.
I've been watching the antiRTFM tutorials on youtube, and they're pretty great. There was one thing that I couldn't quite figure out. There was an expression like so:
y = r*t = x
I do not understand why that causes a compiler error? Is it because r*t isn't a variable that can store the value of x? Would you have to rewrite it as:
1 2
y = x
x = r*t
This would work (through syllogism or transitive property), but is there a more efficient way to do this? Thank you for your time!
Is it because r*t isn't a variable that can store the value of x?
Yes.
1 2 3 4 5 6
// this:
y = r*t = x;
// is the same as this:
r*t = x;
y = r*t;
r*t is not a variable that can be assigned, so that first part makes no sense and causes the compiler error.
Would you have to rewrite it as:
That will work (provided you put semicolons where needed) and is legal syntax... but it has a different meaning. x is being assigned, whereas in the original it wasn't being assigned.... and in the original y was being assigned to r*t, whereas in the rewrite it's being assigned to x.
Then again the original made no sense so it is impossible to come up with an equal statement.
It depends on what you're trying to do I guess.
is there a more efficient way to do this?
there is nothing inefficient about such a basic assignment. So no.
Sorry about the semicolons, again I'm new.
Thanks for the answer, I'll keep that in mind.
I did some more research and this is essentially what I'm trying to say:
y = x = r*t;
I'm setting them all equal to each other. Thanks for the help!