header file and variable declaring problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 30
Reputation: kiwihaha is an unknown quantity at this point 
Solved Threads: 0
kiwihaha kiwihaha is offline Offline
Light Poster

header file and variable declaring problem

 
0
  #1
Apr 19th, 2009
My main code variable declaration (just declaration no login statement)
  1. struct AXEMAN{
  2. int lvl;
  3. int att;
  4. int hp;};
  5. struct DEFENDER{
  6. int lvl;
  7. int att;
  8. int hp;};
  9. struct ARCHER{
  10. int lvl;
  11. int att;
  12. int hp;};
  13. struct SPEARMAN{
  14. int lvl;
  15. int att;
  16. int hp;};
  17. struct ROUGE{
  18. int lvl;
  19. int att;
  20. int hp;};
  21.  
  22. #include "header.h" / have to under struct... so that the struct has been declared
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26. struct AXEMAN axeman;
  27. struct DEFENDER defender;
  28. struct ARCHER archer;
  29. struct ROUGE rouge;
  30. struct SPEARMAN spearman;
  31.  
  32. string input;
  33. int sel_MainMenu=99,sel_GameMenu=99,sel_SubGameMenu=99,sel_Motion=99;
  34. int sel_Movement_num=99;
  35. char sel_Movement;
  36. int sel_char_num=99,sel_enermy_num=99;
  37. char sel_char,sel_enermy;
  38. int comp_dmg,player_dmg,comp_hp,player_hp;
  39. int quit=0;
  40. int error=0;
  41. char matrix[70][50]; //x=70 , y=50
  42. int x,y;
  43. bool detected_comp=0,detected_player=0,skip=0;
==================================================
This code will be called under "header.h" (my subfunction in another .c file)
  1. void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
  2. {
  3. axeman. lvl=1;
  4. axeman. att=40;
  5. axeman. hp=450;
  6. defender. lvl=1;
  7. defender. att=30;
  8. defender. hp=500;
  9. archer. lvl=1;
  10. archer. att=50;
  11. archer. hp=300;
  12. spearman. lvl=1;
  13. spearman. att=45;
  14. spearman. hp=400;
  15. rouge. lvl=1;
  16. rouge. att=35;
  17. rouge. hp=350;
  18. }

PROBLEM:
`ARCHER' was not declared in this scope
`archer' was not declared in this scope

SO:
what is the way i have to declare variable...
or my header file calling method has problem?

thx for help
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: header file and variable declaring problem

 
0
  #2
Apr 19th, 2009
Originally Posted by kiwihaha View Post
  1. struct AXEMAN axeman;
  2. struct DEFENDER defender;
  3. struct ARCHER archer;
  4. struct ROUGE rouge;
  5. struct SPEARMAN spearman;
In C++ you don't have to supply the 'struct' word each time before you declare a struct-variable, though it's still allowed to do so, you can save some typing ...

Edit:: I don't get what you mean, do you have compiler errors ? (please post them if so)
Last edited by tux4life; Apr 19th, 2009 at 12:39 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 30
Reputation: kiwihaha is an unknown quantity at this point 
Solved Threads: 0
kiwihaha kiwihaha is offline Offline
Light Poster

Re: header file and variable declaring problem

 
0
  #3
Apr 19th, 2009
subfunction.cpp:16: error: variable or field `initialize_status_player' declared void
subfunction.cpp:16: error: `AXEMAN' was not declared in this scope
subfunction.cpp:16: error: `axeman' was not declared in this scope
subfunction.cpp:16: error: `DEFENDER' was not declared in this scope
subfunction.cpp:16: error: `defender' was not declared in this scope
subfunction.cpp:16: error: `ARCHER' was not declared in this scope
subfunction.cpp:16: error: `archer' was not declared in this scope
subfunction.cpp:16: error: `SPEARMAN' was not declared in this scope
subfunction.cpp:16: error: `spearman' was not declared in this scope
subfunction.cpp:16: error: `ROUGE' was not declared in this scope
subfunction.cpp:16: error: `rouge' was not declared in this scope
subfunction.cpp:17: error: initializer expression list treated as compound expression
subfunction.cpp:17: error: expected `,' or `;' before '{' token
subfunction.cpp:35: error: variable or field `initialize_status_comp' declared void
subfunction.cpp:35: error: `AXEMAN' was not declared in this scope
subfunction.cpp:35: error: `axeman' was not declared in this scope
subfunction.cpp:35: error: `DEFENDER' was not declared in this scope

subfunction.cpp:35: error: `defender' was not declared in this scope
subfunction.cpp:35: error: `ARCHER' was not declared in this scope
subfunction.cpp:35: error: `archer' was not declared in this scope
subfunction.cpp:35: error: `SPEARMAN' was not declared in this scope
subfunction.cpp:35: error: `spearman' was not declared in this scope
subfunction.cpp:35: error: `ROUGE' was not declared in this scope
subfunction.cpp:35: error: `rouge' was not declared in this scope

subfunction.cpp:36: error: initializer expression list treated as compound expression
subfunction.cpp:36: error: expected `,' or `;' before '{' token
subfunction.cpp: In function `void initialize_weapon(char (*)[50])':
subfunction.cpp:61: error: `random_weapon' undeclared (first use this function)
subfunction.cpp:61: error: (Each undeclared identifier is reported only once for each function it appears in.)

these are part of the error only..
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: header file and variable declaring problem

 
0
  #4
Apr 19th, 2009
OK, can you please attach your code to this thread ?
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 30
Reputation: kiwihaha is an unknown quantity at this point 
Solved Threads: 0
kiwihaha kiwihaha is offline Offline
Light Poster

Re: header file and variable declaring problem

 
0
  #5
Apr 19th, 2009
  1. struct AXEMAN{
  2. int lvl;
  3. int att;
  4. int hp;};
  5. struct DEFENDER{
  6. int lvl;
  7. int att;
  8. int hp;};
  9. struct ARCHER{
  10. int lvl;
  11. int att;
  12. int hp;};
  13. struct SPEARMAN{
  14. int lvl;
  15. int att;
  16. int hp;};
  17. struct ROUGE{
  18. int lvl;
  19. int att;
  20. int hp;};
  21.  
  22. #include "header.h" / have to under struct... so that the struct has been declared
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26. struct AXEMAN axeman;
  27. struct DEFENDER defender;
  28. struct ARCHER archer;
  29. struct ROUGE rouge;
  30. struct SPEARMAN spearman;
  31.  
  32. string input;
  33. int sel_MainMenu=99,sel_GameMenu=99,sel_SubGameMenu=99,sel_Motion=99;
  34. int sel_Movement_num=99;
  35. char sel_Movement;
  36. int sel_char_num=99,sel_enermy_num=99;
  37. char sel_char,sel_enermy;
  38. int comp_dmg,player_dmg,comp_hp,player_hp;
  39. int quit=0;
  40. int error=0;
  41. char matrix[70][50]; //x=70 , y=50
  42. int x,y;
  43. bool detected_comp=0,detected_player=0,skip=0;
  44.  
  45. initialize_board(matrix); //Get Random comp hero
  46. initialize_status_player(axeman, defender, archer, spearman, rouge); //initialize hero's status
  47. introduce();
  48. MainMenu(); //Get the selection of Main Menu
  49. while (sel_MainMenu==99)
  50. {
  51. input=Input();
  52. sel_MainMenu=errorCheck_num (input);
  53. show_error (sel_MainMenu);
  54. }
  55.  
  56. if(sel_MainMenu==1) //If MAIN MENU SELECTION == 1 (new game)
  57. {
  58. initialize_weapon(matrix);
  59. initialize_body (matrix);
  60. }
  61. else if (sel_MainMenu==2)
  62. load (axeman, defender, archer, spearman, rouge);
  63. else
  64. {
  65. cout<<"Bye bye...\n\n\n";
  66. quit=1;
  67. }

  1. void initialize_board(char matrix[][50])
  2. {
  3. for(int i=0;i<70;i++)
  4. for(int j=0;j<50;j++)
  5. {
  6. matrix[i][j]=' ';
  7. }
  8. }
  9.  
  10. void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
  11. {
  12. axeman. lvl=1;
  13. axeman. att=40;
  14. axeman. hp=450;
  15. defender. lvl=1;
  16. defender. att=30;
  17. defender. hp=500;
  18. archer. lvl=1;
  19. archer. att=50;
  20. archer. hp=300;
  21. spearman. lvl=1;
  22. spearman. att=45;
  23. spearman. hp=400;
  24. rouge. lvl=1;
  25. rouge. att=35;
  26. rouge. hp=350;
  27. }
  28.  
  29. void initialize_status_comp(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
  30. {
  31. axeman. lvl=1;
  32. axeman. att=40;
  33. axeman. hp=450;
  34. defender. lvl=1;
  35. defender. att=30;
  36. defender. hp=500;
  37. archer. lvl=1;
  38. archer. att=50;
  39. archer. hp=300;
  40. spearman. lvl=1;
  41. spearman. att=45;
  42. spearman. hp=400;
  43. rouge. lvl=1;
  44. rouge. att=35;
  45. rouge. hp=350;
  46. }
  47.  
  48. void initialize_weapon(char matrix[][50])
  49. {
  50. matrix[4][17]=')';
  51. matrix[4][22]='p';
  52. matrix[4][27]='>';
  53. matrix[4][32]=']';
  54. matrix[4][37]='}';
  55. matrix[55][17]=random_weapon ();
  56. matrix[55][22]=random_weapon ();
  57. matrix[55][27]=random_weapon ();
  58. matrix[55][32]=random_weapon ();
  59. matrix[55][37]=random_weapon ();
  60. }

  1. void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge);
  2. void initialize_board(char matrix[][50]);
  3. void initialize_weapon(char matrix[][50]);

1st code block is my main.c
2nd code block is my subfunction.c
3rd code block is my header.h
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: header file and variable declaring problem

 
0
  #6
Apr 19th, 2009
If this is C++ code you should rename your files to main.cpp, subfunction.cpp and header.h, this will reduce the errors you're having ...
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 30
Reputation: kiwihaha is an unknown quantity at this point 
Solved Threads: 0
kiwihaha kiwihaha is offline Offline
Light Poster

Re: header file and variable declaring problem

 
0
  #7
Apr 19th, 2009
changed but still the same
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: header file and variable declaring problem

 
0
  #8
Apr 19th, 2009
Is this actually your whole code as I can't seem to find the following functions:

> introduce();
> MainMenu();
> Input();
> errorCheck_num (input);
> show_error (sel_MainMenu);
> initialize_body (matrix);
> load (axeman, defender, archer, spearman, rouge);

In the code you posted, the main-function is missing a '}' at the end ...
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC