Sum Function

Hello, I am having trouble with a function I am trying to make. The function is supposed to sum numbers from 2 to 4 numbers used. For some reason I am getting 1 outputted. I tried return num1+num2+num3+num4 , but then I got an error saying named return values no longer supported. So I'm no really sure why that was a problem. Returning result has no errors other than the fact that it doesn't do what it is supposed to haha.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int sum(const int num1, const int num2, const int num3=0, const int num4=0){
    int result = num1+num2+num3+num4;
    return result;
}
int main(){
    sum(4,5,2,3);
    std:: cout<< sum;
    return 0;
}
Function call on line 8 returns a value, but you don't store it.

Line 9 attempts to print something, possibly the address of the function.


See: http://www.cplusplus.com/doc/tutorial/functions/
Ok thanks. Would you happen to know anything about the "return value no longer supported value" error (slightly different code)?
Would you happen to know anything about the "return value no longer supported value" error (slightly different code)?

You had a misplaced opening brace that triggered the error message.

http://ideone.com/Zlc20n

Websearch is your friend.

It does appear that GCC 2.96 had a non-standard syntax for optimization. The feature was short-lived. If you attempt to use that syntax with more recent GCC, you will get this error. If you write code that GCC mistakes as this syntax, you get the error too.
Topic archived. No new replies allowed.