Function in C++ returns by value or by reference?

后端 未结 7 971
醉梦人生
醉梦人生 2020-12-02 14:36

When a function (callee) returns a quantity to the caller function, is it returned by value or by reference?

The thing is I have written a function which builds a ve

7条回答
  •  感情败类
    2020-12-02 15:14

    All variables defined on the stack are cleaned upon exit. To return a variable you should allocate it on the heap, which you do with the new keyword (or malloc).

    Classes and structs are passed around as pointers, while the primitive types are passed around as values.

提交回复
热议问题