Possible Duplicate:
Use the keyword class as a variable name in C++
In a C header file of a library I'm using one of the variables is named 'new'. Unfortunately, I'm using this library in a C++ project and the occurence of 'new' as a variable names freaks out the compiler. I'm already using extern "C" { #include<...> }, but that doesn't seem to help in this respect.
Do I have to aks the library developer to change the name of that variable even though from his perspective, as a C developer, the code is absolutely fine, as 'new' is not a C keyword?
The new operator creates a new instance of a type. You can also use the new keyword as a member declaration modifier or a generic type constraint.
No, new and delete are not supported in C.
The new operator will create arrays of objects only if the class has a default constructor. Specifies the bounds of an array.
Keywords (also known as reserved words) have special meaning to the C++ compiler and are always written or typed in short(lower) cases. Keywords are words that the language uses for a special purpose, such as void, int, public, etc. It can't be used for a variable name or function name.
Before including the header file, use the preprocessor to rename new
:
#define new mynew
#include <...>
#undef new
That will allow the compilation to proceed.
Do you actually need to access this variable? If not - then you're done. If you do, then you'll need to ensure the .c files for the library are compiled with
-Dnew=mynew
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With