1: #include <windows.h>
2: int& max(int& a, int& b)
3: {
4: return a > b ? a : b;
5: }
6: int main()
7: {
8: return 0;
9: }
Visual Studio 2008 Express Edition shouts:
1>e:...\main.cpp(2) : error C2062: type 'int' unexpected
1>e:...\main.cpp(2) : error C2062: type 'int' unexpected
1>e:...\main.cpp(2) : error C2059: syntax error : ')'
1>e:...\main.cpp(3) : error C2143: syntax error : missing ';' before '{'
1>e:...\main.cpp(3) : error C2447: '{' : missing function header (old-style formal list?)
It seems to work if I replace windows.h with stdio.h or iostream (or if I remove it)
Why is this?
windows.his corrupted somehow. Did you happen to open it up in a text editor to look what's in it at some point? You might have mistakenly edited it.max(4, 5)). Don’t be afraid to return by value, it’s efficient and will avoid making unnecessary copies.