Problem with compiling managed c++ code with added c - library

£

£ukasz Z±bik

I have project that uses managed c++ where I use c - library, this library
contains some variables named generic, during compilation I get error: Error
1 error C2146: syntax error : missing ';' before identifier 'generic',
Problem is that in dotNet generic is a keyword, and I cannot change this
name becouse I have only lib file and includes.
How to solve this problem?
 
T

tragomaskhalos

I have project that uses managed c++ where I use c - library, this library
contains some variables named generic, during compilation I get error: Error
1 error C2146: syntax error : missing ';' before identifier 'generic',
Problem is that in dotNet generic is a keyword, and I cannot change this
name becouse I have only lib file and includes.
How to solve this problem?

Are you sure that you don't mean C++/CLI?
No matter:
Add a layer of indirection (the solution to
so many software problems). Write an
ordinary C++ wrapper that avoids using
"generic" in its interface, and call the
wrapper from your "Managed C++".

ie:
library.h
---------
extern void generic(int);

wrapper.h
---------
extern void wrap_generic(int);

wrapper.cpp
-----------
#include "wrapper.h"
#include "library.h"
void wrap_generic(int x) {
generic(x);
}

managed_cpp.cpp
---------------
#if 0 // won't work
#include "library.h" // keyword - bzzt
:
generic(23); // keyword - bzzt
#endif

// this is ok
#include "wrapper.h"
:
wrap_generic(23); // fine

HTH
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top