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

Discussion in 'C++' started by £ukasz Z±bik, Jan 21, 2008.

  1. 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?
     
    £ukasz Z±bik, Jan 21, 2008
    #1
    1. Advertisements

  2. 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
     
    tragomaskhalos, Jan 21, 2008
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.