C++中deprecated笔记

#C++中deprecated接口管理

C++14标准中,假如了[[deprecated]]
其他的都是编译器语法,需要注意兼容

#include 

#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

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

class DEPR_AFTER TestClass1
{
public:
    int m_value;
    void printfValue()
    {
        printf("TestClass:%d", m_value);
    }

} DEPR_BEFOR;

class [[deprecated]] TestClass2
{
public:
    int m_value;
    void printfValue()
    {
        printf("TestClass:%d", m_value);
    }
};

class [[deprecated("Use NeogenePeriod() instead.")]] TestClass3
{
public:
    int m_value;
    void printfValue()
    {
        printf("TestClass:%d", m_value);
    }
};

[[deprecated]] int func_test1()
{
    printf("func_test");
}

[[deprecated("Use NeogenePeriod() instead.")]] int func_test2()
{
    printf("func_test");
}

[[deprecated("Use calcSomethingDifferently(int).")]] int func_test3()
{
    printf("func_test");
}

int main(int argn, char **argv)
{
    auto obj1 = TestClass1();
    auto obj2 = TestClass2();
    auto obj3 = TestClass3();
    func_test1();
    func_test2();
    func_test3();

    printf("Hello World!\n");
    return 0;
}

你可能感兴趣的:(C/C++,c++)