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

前端 未结 7 1465
忘了有多久
忘了有多久 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条回答
  •  萌比男神i
    2020-11-27 07:56

    Like the GMan said the only exception is the main function. I still see tons of books returning 0 in main which isn't really necessary. Oh well I guess it could be worse and you could be learning from a book that uses void main() instead of int main(). But I think what you should learn from all this is that your compiler is complaining for a reason and it's good you took note of it since it will usually save you headaches in the long run.

提交回复
热议问题