用__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; }
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