Message from C, C++ discussions
December 2019
— The same for another tasks.
I was having trouble in other program so i used hello world as a test,however,the header file was not the problem.iosteam also gives a trailing % unless i use endl
— What did mean point&
— /warn Read the rules: no screen photo.
— User Basel has 1/2 warnings; be careful!
The latest warn was because:
Read the rules: no screen photo.
— Read about lvalue& type.
Method returns a reference type of Point class.
— That means that you need to use normal language instead of c++
— Returning a reference in such cases is a good way to UB.
LikePoint& a = Point(10, 20).setX(15);
Or in more sophisticated case:Point& a = (b + c).setX(15);
OrPoint& a = functionThatReturnsPoint().setX();
— No, storing a reference on the stack is the problem here
— Just, unless you get a reference of guaranteed existence, never store a reference
— Someone can see that it's guaranteed in a specific case, then someone else can change the code on the right side so it starts pointing to a temporary.
— I don't see a point of returning a reference here, because 2d point is usually a pod object, so it's copy is cheap