c++ operator overloading memory question

后端 未结 6 2026
挽巷
挽巷 2021-01-01 07:44

In c++ you can create new instances of a class on both the heap and stack. When overloading an operator are you able to instantiate on the stack in a way that makes sense?

6条回答
  •  梦毁少年i
    2021-01-01 08:26

    You are correct that data on the stack is unusable when the function executes. However, it is perfectly okay to return copies of data on the stack (which is what you are doing). Just make sure you don't return pointers to data on the stack.

提交回复
热议问题