C++宏实现的好的代码

C++宏实现的好的代码

#include "errorcode_def.h"
DEFINE_NUWA_ERRORCODE(RequestExecSuccess, 200, "OK");
DEFINE_NUWA_ERRORCODE(ParameterInvalidExceptionError, 400, "ParameterInvalidException");
DEFINE_NUWA_ERRORCODE(FileNotExistExceptionError, 401, "NOT_EXIST")


#include "errorcode.h"
#define DEFINE_ERRORCODE(errorName, httpcode, errorCodestr...) const int errorName = httpcode;
#include "errorcode_def.h"
#undef DEFINE_ERRORCODE

const char* GetErrorString(int errorName);
int GetErrorHttpCode(int errorName);


#include "errorcode.cpp"
const char* GetErrorString(int errorName)
{
    switch(errorName)
    {
    #define DEFINE_ERRORCODE(name, value, errorstr) \
        case name: return errorstr;
    #include "errorcode_def.h"
    #undef DEFINE_NUWA_ERRORCODE
        default:
        {
            return "Unknown_ErrorName";
        }
    }
}


你可能感兴趣的:(C,vs,C++,优秀代码实现)