Scope and return values in C++

前端 未结 6 1212
北恋
北恋 2020-11-30 01:44

I am starting again with c++ and was thinking about the scope of variables. If I have a variable inside a function and then I return that variable will the variable not be \

6条回答
  •  独厮守ぢ
    2020-11-30 02:33

    The local variable is copied to the return value. Copy constructors are called for non-trivial classes.

    If you return a pointer or reference to a local variable you will have trouble---just as your intuition suggested.

提交回复
热议问题