only const static integral data members can be initialized inside a class or struct

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

Join Date: Jun 2007
Posts: 17
Reputation: gattispilot is an unknown quantity at this point 
Solved Threads: 0
gattispilot gattispilot is offline Offline
Newbie Poster

only const static integral data members can be initialized inside a class or struct

 
0
  #1
Jul 19th, 2007
I was told not to have global variables and given an example. Ifollowed it and now I get this error:only const static integral data members can be initialized inside a class or struct
on lines 50-85

  1. #define STRICT
  2. #define ORBITER_MODULE
  3. #define ENG 1
  4. #define START 2
  5. #define STOP 3
  6.  
  7. #include <orbitersdk.h>
  8. #include <cstdio>
  9. #include <cmath>
  10. #include <string>
  11. #include "OrbiterSoundSDK3.h"
  12.  
  13. #include <stdio.h>
  14.  
  15.  
  16.  
  17.  
  18. // ==============================================================
  19. // Shuttle-PB class interface
  20. // ==============================================================
  21.  
  22. class Chariot: public VESSEL2 {
  23. public:
  24. Chariot (OBJHANDLE hVessel, int flightmodel);
  25. // : VESSEL2 (hVessel, flightmodel) {}
  26. void clbkSetClassCaps (FILEHANDLE cfg);
  27. void DefineAnimations(void);
  28. void clbkPostCreation (void);
  29. void clbkPreStep (double simt, double simdt, double mjd);
  30. void clbkPostStep (double simt, double simdt, double mjd);
  31. int clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);
  32.  
  33. private:
  34. double i = 0;
  35. double i2 = 0.5;
  36. double i2l = 0.5;
  37. double i2r = 0.5;
  38. double i3 = 0;
  39. double t1 = 1;
  40. double i4 = 0;
  41. double i5 = 0;
  42. double i6 = 0;
  43. double st = 0;
  44. double pld = 0;
  45. double cen = 0;
  46. double fb = 0;
  47. double sign = 0;
  48. double pit2 = 200;
  49. double sp = 190;
  50. int start = 0;
  51. double i8 = 0;
  52. double main_on = 0;
  53. double retro_on = 0;
  54. THRUSTER_HANDLE th_main;
  55. THRUSTER_HANDLE th_retro;
  56. THRUSTER_HANDLE th_rcs[4], th_group[2];
  57. UINT animactive6;
  58. UINT animactive5;
  59. UINT animactive7;
  60. UINT animactive8;
  61. UINT animactive9;
  62. UINT animactive10;
  63. int MySoundID;
  64. double canopy = 0;
  65. double lfdoor = 0;
  66. double lrdoor = 0;
  67. double rfdoor = 0;
  68. double rrdoor = 0;
  69. double rhatch = 0;
  70. UINT anim_wheel;
  71. UINT anim_wheelleft;
  72. UINT anim_wheelright;
  73. UINT anim_wheelleftrev;
  74. UINT anim_wheelrightrev;
  75. UINT anim_leverleft;
  76. UINT anim_leverright;
  77. UINT anim_lfdoor;
  78. UINT anim_dome;
  79. UINT anim_lrdoor;
  80. UINT anim_rfdoor;
  81. UINT anim_rrdoor;
  82. UINT anim_rhatch;
  83.  
  84. };
  85.  
  86. Chariot::Chariot (OBJHANDLE hVessel, int flightmodel)
  87. : VESSEL2 (hVessel, flightmodel)
  88. {
  89.  
  90. DefineAnimations ();
  91. }
Last edited by ~s.o.s~; Jul 19th, 2007 at 2:43 pm. Reason: Removed the tex tags.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 486
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 48
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: only const static integral data members can be initialized inside a class or struct

 
0
  #2
Jul 19th, 2007
imsorryicantunderstandwhatyourquestionisbecauseitlookslikethis

Try rearranging your post without the LaTex tags

Although, with reference to the subject line - look at the private members in your class (Of which there are far, far too many... if i were you, the first thing i'd do would be to look at a way to cut them down.. such as an array)

You can't directly assign a value to a data member in the class, you need to initialise them in the class constructor instead.
Last edited by Bench; Jul 19th, 2007 at 9:23 am.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 17
Reputation: gattispilot is an unknown quantity at this point 
Solved Threads: 0
gattispilot gattispilot is offline Offline
Newbie Poster

Re: only const static integral data members can be initialized inside a class or stru

 
0
  #3
Jul 19th, 2007
I fixed it. I was told not to have global variables. And send an example

Now I need to see hwta is going on with this:
  1. // --------------------------------------------------------------
  2. // Vessel cleanup
  3. // --------------------------------------------------------------
  4. DLLCLBK void ovcExit (VESSEL *vessel)
  5. {
  6. if (vessel) delete (Chariot*)vessel;
  7. }
  8. void Chariot::clbkPreStep (double simt, double simdt, double mjd)
  9. {
  10. sprintf(oapiDebugString(),"start %2.2f", start );
  11.  
  12. if (0==start){
  13.  
  14. SetThrusterGroupLevel (THGROUP_MAIN, 0);
  15. SetThrusterGroupLevel (THGROUP_RETRO, 0);
  16. SetThrusterGroupLevel (THGROUP_ATT_YAWLEFT, 0);
  17. SetThrusterGroupLevel (THGROUP_ATT_YAWRIGHT, 0);
  18. }
  19. }
What happens is event though start =1 the sprintf shows it is 0 and the set thrusterlevel part doesn't work.
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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC