   Defining variables by a macro
  Ok, this may sound like a weird question, but this is due to database generated files. Using a special script the database table layout is converted to a C++ class which can be used by the application. This saves ALOT of work, however, how do I write such a macro?I tried this:#define M_DEFLONG(VARNAME) LONG m_lVARNAME;  However, that leads to double declarations when calling M_DEFLONG(SomeValue) several times, with different values for SomeValue. Anyone has a clue what the correct macro should look like?Toolmaker   -Earth is 98% full. Please delete anybody you can. 
  You need separate macros for create / access#define M_DEFLONG(VARNAME) LONG m_lVARNAME;  // defines it#define M_USELONG(VARNAME) m_lVARNAME;  // accesses it ;  That''s not gonna work, I am not going to change alot of code for that. There is 1 macro to define the variables(1 macro per type). In the existing code this is already happening, but I dont'' want to change it all.And I don''t have access to the original macro''s either.Toolmaker   -Earth is 98% full. Please delete anybody you can. ;  If you can''t change the code or the macro, what do you expect us to suggest? .   ;  That define is broke, but it may work on some compilers.  You need to tell it to quote the variable name, I think with ''#'', like#define M_DEFLONG(VARNAME) LONG m_l#VARNAME;  but I''m not sure.  You can redefine the macro in your own code, too, here is the magic secret:#undef M_DEFLONG ;  In Soviet Russia, macros define YOU! ;  Hey, actually I''m wrong about using # like that, but I don''t have my preprocessor reference handy, sorry.  Use Google. ;quote:Original post by Toolmaker  That''s not gonna work, I am not going to change alot of code for that. There is 1 macro to define the variables(1 macro per type). In the existing code this is already happening, but I dont'' want to change it all.search and replace using regular expressions. there are plenty of tools you could download.http://www.orbit.org/replace/ ;  Surely the variable is just defined once, I assume that you''re accessing it many times which would be the bulk of the changing work.Therefore I suggest yo uchange the macro that defines them to something like#define M_DEFLONG_CREATE(VARNAME) LONG m_lVARNAME;and the usage macro to:#define M_DEFLONG(VARNAME) m_lVARNAME;That way, you only have to change the areas where the variables are actually defined and not accessed. ;  You guys are way off, he''s just declaring a variable named "m_lVARNAME" every time he calls the macro, no matter what argument he gives it.  That''s the main problem.Check the output from your preprocessor. 