The stringify() macro can be used to turn any text in your code into a string, but only the exact text between the parentheses. There are no variable dereferencing or macro substitutions or any other sort of thing done.


/////////////////////////////////////////////////
#define stringify( name ) # name enum enMyErrorValue { ERROR_INVALIDINPUT = 0, ERROR_NULLINPUT, ERROR_INPUTTOOMUCH, ERROR_IAMBUSY }; const char * enMyErrorValueNames[] = { stringify( ERROR_INVALIDINPUT ), stringify( ERROR_NULLINPUT ), stringify( ERROR_INPUTTOOMUCH ), stringify( ERROR_IAMBUSY ) }; void vPrintError( enMyErrorValue enError ) { cout << enMyErrorValueNames[ enError ] << endl; } int main() { vPrintError((enMyErrorValue)1); }
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JohnDX 的頭像
    JohnDX

    我要回家想一想~

    JohnDX 發表在 痞客邦 留言(0) 人氣()