Makro's (#define)...different Variable names
-
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...
-
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...
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? -
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?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
-
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
-
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 eachoErr
variable lives in its own scope.