I have
enum class ErrorLevel
{
VERBOSE,
DEBUG_,
INFORMATION,
WARNING,
ERROR
};
This works:
assertDetectionParameters( parameterSet, ErrorLevel::WARNING );
This does not:
assertDetectionParameters( parameterSet, ErrorLevel::ERROR );
Error 1 error C2589: 'constant' : illegal token on right side of '::'
Error 2 error C2059: syntax error : '::'
Resharper says:
"ErrorLevel does not name a value"
I get this error for certain names in my enum.
ERROR is probably already a preprocessor macro somewhere. Try changing it to something else, e.g. ERROR_, in order to test this hypothesis. Alternatively run your code through the preprocessor to see what substitutions are being made (gcc -E ... or whatever the equivalent is in Visual Studio).
Related
I'm usually a g++ user. And I loved it for it's simplicity, but I'm trying to test compiling a native executable because usually I create a static which is really heavy in size. But I'm having some errors.
One on this line : return in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
warning C4003: not enough arguments for function-like macro invocation 'max'
file.cpp(95): error C2589: '(': illegal token on right side of '::'
file.cpp(95): error C2144: syntax error: 'unknown-type' should be preceded by ')'
file.cpp(95): error C2144: syntax error: 'unknown-type' should be preceded by ';'
file.cpp(95): error C2059: syntax error: ')'
and here
DWORD mxpath = MAX_PATH;
char ld[mxpath];
error C2131: expression did not evaluate to a constant
sas.cpp(76): note: failure was caused by a read of a variable outside its lifetime
sas.cpp(76): note: see usage of 'mxpath'
I don't understand what I'm doing wrong as this code works with g++ without any errors. I'm new to msvc and I wanted to see if it is better than compiling a g++ static.
Why are those errors coming?
When trying to compile the following C++ code snippet (using Microsoft Visual Studio 2015):
namespace NS
{
const int ERROR = -1;
};
It returns the following error:
c:\workspace\X.hpp(141): error C2143: syntax error: missing ';' before 'constant'
c:\workspace\X.hpp(141): error C2059: syntax error: 'constant'
The constant ERROR is already defined somewhere, since if one makes the line a comment, ERROR can still be printed (it returns 0 for that matter).
I thought this type of collision could be avoid by defining a namespace.
How can one defined his/her own constant ERROR?
I have the following code which compiles without errors under Linux and Mac OS X. I now want to compile the code with Windows, but I get a lot of errors in the following code segment:
...
enum Type
{
UPDATE = 0, DELETE = 1
};
...
The error messages are these:
1>Request.hpp(48) : error C2143: syntax error : missing '}' before '('
1>Request.hpp(48) : error C2059: syntax error : '<L_TYPE_raw>'
1>Request.hpp(49) : error C2143: syntax error : missing ';' before '}'
1>Request.hpp(49) : error C2238: unexpected token(s) preceding ';'
What did I wrong, I am really confused, as this compiles without errors under Linux.
What can cause this errors?
The solution is quite easy, but one need to find out that DELETE is a Macro defined in the windows header.
I now added #undef DELETE and it works fine.
Type is an existing class. You need to change the name or specify that it's a literal.
You could try enum #Type to specify a literal, though you may need to prefix it with # elsewhere.
I'm working with quite a big codebase which compiles fine in linux but vc++ 2008 spits errors.
The problem code goes like this:
Declaration:
typedef float vec_t;
typedef vec_t vec2_t[2];
The codebase is littered with in-place construction like this one:
(vec2_t){0, divs}
Or more complex:
(vec2_t){ 1/(float)Vid_GetScreenW(), 1/(float)Vid_GetScreenH()}
As far as I know, this code constructs a struct, then converts it to an array and passes the address to the function. I personally never used in-place construction like this so I have no clue how to make this one work.
The compiler produces a bunch of syntax errors like these:
Error 2 error C2143: syntax error : missing ')' before '{'
Error 3 error C2059: syntax error : ')'
Error 4 error C2143: syntax error : missing ';' before '{'
I don't maintain the linux build, only the windows one. And I can't get it to compile. Is there some switch, some macro to make vc++ compile it?
Maybe there is a similar nifty way to construct those arrays and pass them to the functions in-place that compiles just fine in vc++?
You're using a GCC extension that MSVC simply doesn't support, "compound literals", also called "constructor expressions" in older GCC docs.
If you want portable code, I think you'll need to change the code to declare the structs normally and initialize them with initializers that have constants expressions or using standard assignments (or use something like MinGW as your Windows compiler, if that'll do the trick).
I believe this is a language extension, supported by GCC that probably isn't available in MSVC. You can look around for a "Constructor Expression" in your docs, but your only solution might be to get a GCC for windows. See:
Constructor Expressions
If you simply want to compile your codes under Windows and it doesn't have to use MSVC, have you tried using GCC? it might be caused by specific extensions of GCC.
typedef float vec_t;
typedef vec_t vec2_t[2];
vec_t Vid_GetScreenW()
{
return 600.f;
}
vec_t Vid_GetScreenH()
{
return 300.f;
}
int main() {
vec_t divs = 3.f;
//The codebase is littered with in-place construction like this one:
vec_t* vec1 = (vec2_t){0, divs};
//Or more complex:
vec_t* vec2 =
(vec2_t){ 1/(float)Vid_GetScreenW(), 1/(float)Vid_GetScreenH()};
return 0;
}
The snippet above compiles with g++ (MinGW) under Windows XP and produce the following error using cl.exe:
E:\tmp>g++ vec.cc
E:\tmp>cl vec.cc Microsoft (R) 32-bit
C/C++ Optimizing Compiler Version
14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation.
All rights reserved.
vec.cc vec.cc(16) : error C2059:
syntax error : '{' vec.cc(16) : error
C2143: syntax error : missing ';'
before '{' vec.cc(16) : error C2143:
syntax error : missing ';' before '}'
vec.cc(19) : error C2059: syntax error
: '{' vec.cc(19) : error C2143: syntax
error : missing ';' before '{'
vec.cc(19) : error C2143: syntax error
: missing ';' before '}'
I have a code that generates errors on my PC but does't on other PC.I have windows 7 installed and also installed the compatible SDK for windows 7.I have also included the VC directories (from Tools -> option-> vc Diretories) but still the code generates follwing errors.
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
error C2589: '(' : illegal token on right side of '::'
warning C4091: '' : ignored on left of 'const unsigned int' when no variable is declared
error C2143: syntax error : missing ';' before '::'
error C2059: syntax error : '::'
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
statement generating error are as following
static const unsigned int MAPVK_VK_TO_CHAR;
const unsigned int KeyLogger :: MAPVK_VK_TO_CHAR = 0x02;
Try selecting MAPVK_VK_TO_CHAR and hitting F12 to see if the symbol is declared elsewhere.
What's MAPVK_VK_TO_CHAR? I ask because the error might indicate that this is some macro.
Why do you make a plain identifier (not a macro) all caps, anyway? That's just begging for one of the thousands of macros in <windows.h> to trample over it. (Not that not making it all caps would prevent that, since <windows.h> sacrilegiously defines many mixed-case macros...)
Otherwise you would have to paste some minimal, compilable example showing the problem.