none
define enum as macros

    Question

  • n the header file stdafx.h i defined the follows

    #define

     

    BEGIN_TM_ENUM(name) enum name {

    #define

     

    END_TM_ENUM() };

     

     

    in the .cpp file included stdafx.h and defining the enum values

       

     

    Error 4 error C2365: 'TTIBES_NORMAL' : redefinition; previous definition was 'enumerator'

    BEGIN_TM_ENUM(TOPTABITEMBOTHEDGES)

    TM_STATE(1, TTIBES, NORMAL)

    END_TM_ENUM()

    the following is the error it shows

     

    Monday, February 22, 2010 11:44 AM

Answers

  • 
    BalajiAtMS wrote:
    > n the header file stdafx.h i defined the follows
    >
    > #define BEGIN_TM_ENUM(name) enum name {
    > #define END_TM_ENUM() };
    >
    > in the .cpp file included stdafx.h and defining the enum values
    >
    > Error 4 error C2365: 'TTIBES_NORMAL' : redefinition; previous definition was 'enumerator'
    >
    > BEGIN_TM_ENUM(TOPTABITEMBOTHEDGES)
    > TM_STATE(1, TTIBES, NORMAL)
    > END_TM_ENUM()
    > the following is the error it shows
     
    What's TM_STATE?
     
    Somehow, you managed to define TTIBES_NORMAL twice in two different places. The next line in the error report usually points you to the previous declaration.
    --
    Igor Tandetnik
    • Marked as answer by Wesley Yao Monday, March 01, 2010 2:53 AM
    Monday, February 22, 2010 12:43 PM

All replies

  • 
    BalajiAtMS wrote:
    > n the header file stdafx.h i defined the follows
    >
    > #define BEGIN_TM_ENUM(name) enum name {
    > #define END_TM_ENUM() };
    >
    > in the .cpp file included stdafx.h and defining the enum values
    >
    > Error 4 error C2365: 'TTIBES_NORMAL' : redefinition; previous definition was 'enumerator'
    >
    > BEGIN_TM_ENUM(TOPTABITEMBOTHEDGES)
    > TM_STATE(1, TTIBES, NORMAL)
    > END_TM_ENUM()
    > the following is the error it shows
     
    What's TM_STATE?
     
    Somehow, you managed to define TTIBES_NORMAL twice in two different places. The next line in the error report usually points you to the previous declaration.
    --
    Igor Tandetnik
    • Marked as answer by Wesley Yao Monday, March 01, 2010 2:53 AM
    Monday, February 22, 2010 12:43 PM
  • 
    D.Sreedhar wrote:
    > You can't mix C++ and CPP (preprocessor) data.
     
    Why not?
     
    > So if the argument to the macro is a C++ variable/const/whatever it won't work.
     
    Macros are just text substitutions. Their arguments are strings of text. They don't know nor care whether these strings of text might happen to be variable names or whatever.

    > Also, you can't use enum like that.
     
    Like what?
    --
    Igor Tandetnik
    Monday, February 22, 2010 1:03 PM