Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C++ allow default return types for functions?

Tags:

c++

c

In C the following horror is valid:

myFunc()
{
  return 42;  // return type defaults to int.
}

But, what about in C++? I can't find a reference to it either way...

My compiler (Codegear C++Builder 2007) currently accepts it without warning, but I've had comments that this is an error in C++.

like image 950
Roddy Avatar asked Dec 01 '08 15:12

Roddy


1 Answers

It's ill-formed in C++. Meaning that it doesn't compile with a standard conforming compiler. Paragraph 7.1.5/4 in Annex C of the Standard explains the change "Banning implicit int".

like image 186
Johannes Schaub - litb Avatar answered Nov 15 '22 04:11

Johannes Schaub - litb