Functions with return values (C++)

前端 未结 6 1092
南旧
南旧 2020-12-11 23:10

When main() calls a function which has a return value of some datatype ( primitive or user-defined ) , the statement in which the function is called is \'usually\' an assign

6条回答
  •  [愿得一人]
    2020-12-12 00:02

    It gets assigned into a temporal (invisible if you may) complex value. The lifetime of such value is until the expression that generated it ends, that's the ; at the end of c1+c2. So a new temporal object is created to store the result of the expression, and its destructed at the end of that line.

    You shouldn't be modifying 'this' in your a + b operator, after evaluating a + b now a holds the result of the expression.

提交回复
热议问题