'static ' : ignored on left of 'const double' when no variable isdeclared

2

2b|!2b==?

I'm getting this rather cryptic com,pile time error when I compile my
code. I have the following lines in my header file I know I could use
anonymous namespaces to get around this but I was being lazy and simply
wanted to do it the old "C" way).

The header looks like this:

#pragma once

......

#define maximum std::max<double>
static const double ACCURACY=1.0e-6; <- compiler barfs here
static const double ERROR=-1e30;


???
 
C

Chris Taylor

Hi,

The problem is most likely with the following line
static const double ERROR=-1e30;

ERROR is defined as a macro which the preprocessor is expanding therefore
making causing this to not be valid a variable declaration.

Hope this helps
 
D

Doug Harrison [MVP]

I'm getting this rather cryptic com,pile time error when I compile my
code. I have the following lines in my header file I know I could use
anonymous namespaces to get around this but I was being lazy and simply
wanted to do it the old "C" way).

The header looks like this:

#pragma once

.....

#define maximum std::max<double>
static const double ACCURACY=1.0e-6; <- compiler barfs here
static const double ERROR=-1e30;


???

When you get an error like this, the first thing to do is copy the
offending line and paste it into a file all by itself. When you find it
compiles OK, and in this case it does for me, look for differences between
the test file and the real compilation environment. As you are using
all-caps for a variable name, and all-caps at least informally is usually
restricted to macros, I'd suspect a conflicting macro definition. You can
compile with /P to review the preprocessor output or simply change the case
a bit to see if that helps.
 
N

Nathan Mates

#define maximum std::max<double>
static const double ACCURACY=1.0e-6; <- compiler barfs here
static const double ERROR=-1e30;

Sometimes, the error is on the line, or the line before.
I'd insert a test line between the #define and the ACCURACY line,
e.g.

#define ...
extern double g_SomeDoubleTestValue;
static const double ...

If it still errors out line after the #define, then the real error
lies above it -- might be a class Foo {} without the closing
semicolon, or something else.

Nathan Mates
 
T

Tom Widmer [VC++ MVP]

2b|!2b==? said:
I'm getting this rather cryptic com,pile time error when I compile my
code. I have the following lines in my header file I know I could use
anonymous namespaces to get around this but I was being lazy and simply
wanted to do it the old "C" way).

The header looks like this:

#pragma once

.....

#define maximum std::max<double>
static const double ACCURACY=1.0e-6; <- compiler barfs here
static const double ERROR=-1e30;

In addition to the other responses (which indicate the cause of the
error), static here is redundant - const variables at namespace scope
are implicitly "static" anyway, so you can leave off the static keyword.
If you want them to be extern (which you don't of course), you have to
explicitly add extern.

Tom
 
N

Norman Diamond

Error 1: 2b|!2b!=the question. 2b|~2b==the question. Hamlet computed ff
because he operated on bitwisecracks.

Error 2: As Chris Taylor suggested, I think the preprocessor is expanding
the ERROR macro as it's probably supposed to (if you're including just about
any of the common standard headers) and the result is rather cryptic
syntactic garbage in the line after the one you pointed to. At least you're
lucky it didn't result in valid syntax with some meaning completely
different from what you wanted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top