Shadowing?

Hello writing a function currently and when I try to make a parameter list with char values it says that my code is shadowing? Could anyone help with?

Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  1 //Sam Vernaza CS162 Lab # 4 
  2 // Practice with functions
  3 #include <iostream>
  4 #include <cctype>
  5 #include <cstring>
  6 
  7 using namespace std;
  8 
  9 // prototypes here:
 10 
 11 const int  NAME = 21;
 12 const int ARRAY= 22;
 13 const int CRNNAME = 4;
 14 
 15 void user_name (char first [], char last []); //username void function
 16 void course (int crn[], char course [], int section[]);// coures void function
 17 
 18 
 19 
 20 int main()
 21 {
 22     char first[NAME]; // First name array
 23     char last [ARRAY]; // First name array
 24 
 25      user_name(first,last); // function call
 26 
 27      return 0;
 28 }
 29 
 30 void user_name (char first[], char last [])
 31 {
 32     char first[NAME];
 33     char last[ARRAY];
 34     char response;
 35 
 36     cout << "Enter First Name:" << endl;
 37     cin.get(first,NAME,'\n');
 38     cin.ignore(100,'\n');
 39     response = toupper(first[0]);
 40 
 41 
 42     cout << "Enter Last Name;" << endl;
 43     cin.get(last,ARRAY,'\n');
 44     cin.ignore(100,'\n');
 45     response = toupper(last[0]);
 46 
 47     cout << "You've Entered: " << endl;
 48 }
Lines 32 and 33 hide the parameters because they have same names. You don't need to declare parameters again in the function body. Just the signature is enough.
Thank you for the reply, but I really am new to this and I need help understanding what all of that means. Please?
You have declared two variables, first and last on line 30, being the parameters taken by the function. Then, on line 32 and 33, you have declared two more variables with the same name, which 'hide' the variables from line 30.

This means that changes to first and last from then will not be reflected in main. However, in your case you wouldn't notice, because you aren't using the results taken in the parameter list for the function anyway (I presume you will later, though).
Thanks. Ok then, what about when I need to declare an array length? How would I represent that in my function?
You can say
 
void user_name (char first[NAME], char last[ARRAY])
BUT this doesn't actually do anything compared to what you have now. The compiler doesn't use this information for anything.
Topic archived. No new replies allowed.