No, this is not safe. GCircle::GetCentre() return-by-value, so the memory in which the return value is temporarily stored will be invalid at the end of the statement. Assigning a part of the data to a reference variable really only stores a pointer to the source address in memory. When this memory is invalid, Centre can refer to any memory of any type and will blindly treat it like a GPoint .
To keep the value returned by value, you need to say GPoint Centre = circle.GetCentre(); . If you really need a reference to the circle c_Centre member, you should rewrite GetCentre() as such:
GPoint& GetCentre() const {return c_Centre;}
Also, since you probably don't want people outside of circle change their center, you should probably return it as const GPoint& :
const GPoint& GetCentre() const {return c_Centre;}
This will lead to the fact that anyone looking at the new local variable Centre will think about its const without changing the way they view the circle the same piece of data.
source share