Pass by reference (Function within function)

Let's say I have this function that I use to change some values in an instance of the class employer. I pass the instance by reference.
Q1) Is it possible to call calc_employer (Employer& emp) from within set_employer() to make some calculations and replace numerical values of the instance?
Q2) When control returns to set_employer(), will the changes made by calc_employer be available
Q3) Why should I avoid doing this?

1
2
3
4
5
6
7
8
9
void set_employer (Employer& emp1)
{
   ...
   calc_employer (emp1)
   ...
}

void calc_employer (Employer& emp)
{...}


PS: I guess this will enrage Duoas, but I beg for forgiveness Lord of C++.
Last edited on
A1) you have to declare (or define) calc_employer before calling it. example:
1
2
3
4
5
6
7
8
9
10
11
void calc_employer (Employer& emp);//a function declaration.

void set_employer (Employer& emp1)
{
   ...
   calc_employer (emp1)
   ...
}

void calc_employer (Employer& emp)
{...}

A2) yes.
A3) you shouldn't avoid this at all.
Thanks for the answer I was hoping for.
Topic archived. No new replies allowed.