When I create myupper, I want the ToUpper() function to MOVE the value of my into myupper
I notice that my Move Constructor doesn't get called in this case, but the function just creates a COPY (exactly what I don't want) of the whole GString object.
I've heard about creating the Move Assignment also.
But it's strange because this I've written with the GString class works fine with my GList class:
But when I return, how do I move instead of copying?
You just return. You're getting a more efficient strategy than moving or copying with copy elision. However, if for some reason you feel like you want to force a less efficient strategy, then use std::move in your return statement.
What's the rule here? When does it / doesn't it get called?
There isn't a hard and fast rule (except as to when it can't happen.) I suppose the rule is to return and let the compiler sort out the most efficient way to do things. ;)
My guess would be that the difference you observed is in the compiler optimization settings. If you're using VC++, it typically forgoes copy elision in the default debug configuration.
I read from Bjarne Stroustrup book that when returning a large class object I should use a Move operation instead of a COPY (for obvious reasons)
So yeah, let's pretend GString is a very huge class.
I would NEVER want my computer to make a COPY of that object, so I define a Move Constructor... that doesnt get invoked lol
I dont understand the reason of this. It should perform a Move instead of a copy since I explicitly defined a Move Constructor