用__attribute__((deprecated)) 管理过时代码,同一时候保留兼容的接口

Linux下:

#define  DEPR_AFTER __attribute__((deprecated))
#define  DEPR_BEFOR 


class DEPR_BEFOR AAA
{
}DEPR_AFTER;

int main(int argc, char** argv)
{
    typedef float T;
    AAA aa;

    return 0;
}

g++ main.cpp -o main

main.cpp: In function ‘int main(int, char**)’:
main.cpp:16:9: warning: ‘AAA’ is deprecated (declared at main.cpp:9) [-Wdeprecated-declarations]


WINDOWS下:

对于VC。类似如OPENCV定义:

#if defined __GNUC__
    #define __CV_GPU_DEPR_BEFORE__
    #define __CV_GPU_DEPR_AFTER__ __attribute__ ((deprecated))
#elif defined(__MSVC__) //|| defined(__CUDACC__)
    #pragma deprecated(DevMem2D_)
    #define __CV_GPU_DEPR_BEFORE__ __declspec(deprecated)
    #define __CV_GPU_DEPR_AFTER__
#else
    #define __CV_GPU_DEPR_BEFORE__
    #define __CV_GPU_DEPR_AFTER__
#endif