CW7.0 Pro: MCF52223: Static Const Initialization: Error "Illegal constant expression"

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CW7.0 Pro: MCF52223: Static Const Initialization: Error "Illegal constant expression"

2,540 Views
nbonwit
Contributor I

Hello,

I'm getting a strange compiler error.  My code (located in a header file) is as follows:

namespace myNamespace
{
 class Globals
    {
     public:  
         static const double myDouble= 6.9;
         static const int myInt= 6;
         ...
    };
}

I get the compiler error "Illegal constant expression" on the line "static const double myDouble= 6.9;", but not on the line with " static const int myInt= 6;".  In fact, the compiler gives that error for all doubles, but integers, shorts, and bools seem to be fine

Any help would be appreciated.

Thanks,
Neville



Message Edited by nbonwit on 2008-04-07 06:32 AM
Labels (1)
0 Kudos
Reply
2 Replies

529 Views
CompilerGuru
NXP Employee
NXP Employee
That's the way C++ is defined,
non integral constants must be defined out of the class in a separate definition in a *.cpp file.

Daniel


Code:
example.h: class Globals {     public:           static const double myDouble;  ...example.cpp:#include "example.h"const double Globals::myDouble= 6.9;

 

0 Kudos
Reply

529 Views
nevilleb
Contributor I
Hello Daniel,
 
Thanks so much for your help.  I'll do as you suggest.
 
Neville
0 Kudos
Reply