Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Article Writing
  4. Makro's (#define)...different Variable names

Makro's (#define)...different Variable names

Scheduled Pinned Locked Moved Article Writing
5 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 1354
    wrote on last edited by
    #1

    Is there a way to define a makro like this: #define NEW_VAR CString str__Line__ The compiler should make out of: void CMyClass::Test() { NEW_VAR NEW_VAR } something like : void CMyClass::Test() { CString str123 CString str124 } out of it. I dont care about the Lines. I just want to define a marko witch declares a Variable. And I want to use it more then 1 time in a function. Thank you...

    U 1 Reply Last reply
    0
    • U User 1354

      Is there a way to define a makro like this: #define NEW_VAR CString str__Line__ The compiler should make out of: void CMyClass::Test() { NEW_VAR NEW_VAR } something like : void CMyClass::Test() { CString str123 CString str124 } out of it. I dont care about the Lines. I just want to define a marko witch declares a Variable. And I want to use it more then 1 time in a function. Thank you...

      U Offline
      U Offline
      Uwe Keim
      wrote on last edited by
      #2

      Even if it could, how would you access the variables? By name? I don't believe, since you don't know their names. This would be just good for objects like CWaitCursor or so, which has just a constructor and a destructor. But those objects, you don't need more than one per scope, do you? So what should this be good for?

      U 1 Reply Last reply
      0
      • U Uwe Keim

        Even if it could, how would you access the variables? By name? I don't believe, since you don't know their names. This would be just good for objects like CWaitCursor or so, which has just a constructor and a destructor. But those objects, you don't need more than one per scope, do you? So what should this be good for?

        U Offline
        U Offline
        User 1354
        wrote on last edited by
        #3

        OK...I try to explain it: We got an ErrorClass (EFErr). We need our ErrorClass in nearly every function. Usually we use it like that: EFErr CTest::Tester(...) { EFErr oErr=Hallo(...); //Funktion Hallo returns a EFErr too if (oErr) //Check if a error accours { return oErr; //return this error } } I want to reduce the code with an Makro: #define RET_FUNKTION(function) EFErr oErr=function;if (oErr){return oErr}; so I can do the same like above with: RET_FUNKTION(Hallo(...)) ...so long... ...but there is a problem: I can use this makro just one time in my function. I cant do things like that: EFErr CTest::Tester(...) { RET_FUNKTION(Hallo(...)) RET_FUNKTION(Hallo2(...)) } because the Variable oErr is redifined the second time. Of course, I can shorten the makro to: #define RET_FUNKTION(function) oErr=function;if (oErr){return oErr}; but then I have to do it like that: EFErr CTest::Tester(...) { EFErr oErr; RET_FUNKTION(Hallo(...)) RET_FUNKTION(Hallo2(...)) } If I could use the Line in the Variable name like: #define RET_FUNKTION(function) EFErr oErr__Line__=function;if (oErrr__Line__){return oErrr__Line__}; it will work... ...I hope this discribes my problem

        U 1 Reply Last reply
        0
        • U User 1354

          OK...I try to explain it: We got an ErrorClass (EFErr). We need our ErrorClass in nearly every function. Usually we use it like that: EFErr CTest::Tester(...) { EFErr oErr=Hallo(...); //Funktion Hallo returns a EFErr too if (oErr) //Check if a error accours { return oErr; //return this error } } I want to reduce the code with an Makro: #define RET_FUNKTION(function) EFErr oErr=function;if (oErr){return oErr}; so I can do the same like above with: RET_FUNKTION(Hallo(...)) ...so long... ...but there is a problem: I can use this makro just one time in my function. I cant do things like that: EFErr CTest::Tester(...) { RET_FUNKTION(Hallo(...)) RET_FUNKTION(Hallo2(...)) } because the Variable oErr is redifined the second time. Of course, I can shorten the makro to: #define RET_FUNKTION(function) oErr=function;if (oErr){return oErr}; but then I have to do it like that: EFErr CTest::Tester(...) { EFErr oErr; RET_FUNKTION(Hallo(...)) RET_FUNKTION(Hallo2(...)) } If I could use the Line in the Variable name like: #define RET_FUNKTION(function) EFErr oErr__Line__=function;if (oErrr__Line__){return oErrr__Line__}; it will work... ...I hope this discribes my problem

          U Offline
          U Offline
          Uwe Keim
          wrote on last edited by
          #4

          Just more scope :-) What I would do is to use two brackets {}: #define RET_FUNKTION(function) **{** EFErr oErr=function;if (oErr){return oErr}; **}**. then you have no problem, since each oErr variable lives in its own scope.

          U 1 Reply Last reply
          0
          • U Uwe Keim

            Just more scope :-) What I would do is to use two brackets {}: #define RET_FUNKTION(function) **{** EFErr oErr=function;if (oErr){return oErr}; **}**. then you have no problem, since each oErr variable lives in its own scope.

            U Offline
            U Offline
            User 1354
            wrote on last edited by
            #5

            Ich danke vielmals.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups