Help with operator overloading

#include <iostream>
using namespace std;

int a (int num);
int b (int num2);

int a (int num)
{
        num += 5;
        return num;
}

int b (int num2)
{
        num2 += 10;
        return num2;
}

int main ()
{
        int num;
        int num2;
        int sum;

        cout << "Enter first number: ";
        cin >> num;

        cout << endl << "enter second number: " << endl;

        a (num);
        b (num2);


        sum = a(num) operator+ b(num2); //ERROR occurs here

        cout << "the sum of 15 + your numbers is: " << sum;
}


This is the example program I typed up to practice, I get the error "expected ; before operator" but putting a semi colon there doesn't make it work.

Operator overloading is generally done to provide builtin operator functionality for user-defined types. You are trying to call the operator+ function on 2 integers. You have 2 functions that return ints, not 2 classes.

To better understand operator overloading, see this tutorial page from this site:
http://www.cplusplus.com/doc/tutorial/templates/

p.s. You never read in the second value.
Last edited on
Thanks for the reply, I'll check it out!
Topic archived. No new replies allowed.