Is it possible to make this operator function outside of a class? For example, I want to find the sum of 2 integer variables. I know the simplest solution is just, int x + int y, but is it possible to call a function to do this?
I'm not exactly sure what you are asking. you can do
1 2 3 4 5 6 7 8 9 10
int addition(int x, int y); //this makes sure your program can find the addition function
//and can be added into a header file
int main(){
int var = addition(5, 80); //calling the function
return 0;
}
int addition(int x, int y){ //this is a function
return x+y;
}
you cannot overload an operator that is not in a class.
1 2 3 4 5 6 7
intoperator+(int a){ //error, not in a class
return a;
}
int main(){
return 1+-1;
}