Is a return statement mandatory for C++ functions that do not return void?

前端 未结 7 1470
忘了有多久
忘了有多久 2020-11-27 07:31

My Herb Schildt book on C++ says: \"... In C++, if a function is declared as returning a value, it must return a value.\" However, if I write a function wit

7条回答
  •  情书的邮戳
    2020-11-27 08:10

    Yes, it must return a value.

    Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.

    This question will bring more light to the subject

提交回复
热议问题