944,117 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10728
  • C++ RSS
Jul 19th, 2007
0

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

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gattispilot is offline Offline
17 posts
since Jun 2007
Jul 19th, 2007
0

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

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.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Jul 19th, 2007
0

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

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:
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gattispilot is offline Offline
17 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: convert these C++ codes to VB .NET ?
Next Thread in C++ Forum Timeline: How to convert WideString to THashString?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC