Returning Values in Functions?

I understand that when you put things in the parentheses

1
2
3
4
5
6

int example(int a, int b)
{
  // code here
}


you can use the function with other variables. I'm wondering if however when you return a variable if you can use it in other .cpp files. I have an integer that tells the program what kind of race the user is, but I'd prefer not to have it as a global variable.
what you could do is have what most people call a "getter" function and have that function be declared globally and have it just return the race variable, but define that variable and the function in a separate .cpp file.

1
2
//race.h
int get_race();

1
2
3
//race.cpp
int race;
int get_race(){return race;}
Topic archived. No new replies allowed.