   How do I define a constant expression with in a class?
  My program was written using GCC and now I''m trying to port it to MSVC++ 6.0 (which is proving to be a big headache).  I''ve managed to fix most of the errors, but there is one big problem that VC++ bitches about that GCC doesn''t care about: class MyClass {   static const int MY_CONST = 1234;};  I get the errors :error C2258: illegal pure syntax, must be ''= 0''error C2252: ''MY_CONST'' : pure specifier can only be specified for functions  This can be fixed by putting the constant in the source file instead of the header file.  But there is one case where I can''t move it: class OtherClass{   static const int MY_CONST; // this is assigned a value in the source file instead of here    int arr[OtherClass::MY_CONST];};  Now, if I try to compile it, error C2057: expected constant expressionwarning C4200: nonstandard extension used : zero-sized array in struct/union  Is there some way to fix this knot?  Thanks for your help.  
  class foo{enum { bar = 1; }// ...};  ;  First, static and const are redundant, and I believe static can only be used for functions, though I might be wrong.  I would recommend whacking the static part of your code and trying again.  That should fix the problem.  Otherwise, use an enumeration (enum).Then again, I''m one of the most hated people in all of computer programming...a Borland user.  Ahh!  Run for your lives! ;  Whats''s wrong with Borland?At least Borland lets you do:for (int i=sometging; blah; blah)for (int i=sometging; blah; blah)for (int i=sometging; blah; blah)But MS complains about the earlie declaration of i. Bah.  ;  If you want to use a static member it should be:const static int MY_CONST = 1234;not:static const int My_CONST = 1234;It should work fine then. Lektrix[ Google || ACCU || BarrysWorld || E-Mail Me ]  ;quote:Original post by __tunjin__  class foo{enum { bar = 1; }// ...};  This is the correct answer.  ;quote:Original post by Racso  First, static and const are redundant, and I believe static can only be used for functions, though I might be wrong.  Actually, you''re wrong on both accounts. Static and const are two completely different things. He wants a single constant used by all instances of the class. If he did just static, then the value would be editable, if he did just const, then there would be an instance of it in every single object! He doesn''t want either of those he wants them both at the same time. Thinking static is only applicable to functions makes me think that you probably don''t understand what static means.Anyways, the enum version is the best -- while it doesn''t make a constant in memory, it gives the same effect as what you want (unless at some point you want to use the value''s memory address because with an enum it won''t have one). Don''t put extra stuff in memory when you can avoid it. Enumerations are fine in this case.;  In a .h fileclass foo{public:static const int CONST;}in a .cppconst int foo::CONST = 1234;  ;quote:Original post by Anonymous Poster  In a .h fileclass foo{public:static const int CONST;}in a .cppconst int foo::CONST = 1234; He knows he can do that, but his point is that he has another variable in the class that is dependent on the value. In this case, what you mentioned will not solve his problem. Using enum is what he should be doing.  ;  That''s realyl a bit of a language flaw isn''t it? The enum thing works, but it''s a hack.    "That''s not a bug, it''s a feature!"  --me  