Can I prevent nested deprecated method calls from warnings?

I have some library code that has legacy code that I would like to move away with. For this, I began to mark deprecated methods as deprecated. Where these methods call each other, I get deprecation warnings that I would rather not see (new functionality means you only need one call since there are fewer internals for how the classes work).

Is there a way to suppress the rejection warning for a call from OldMethod

to OldMethodHelper

? .. or a better way to do it at all?

For example (in MyClass.h

):

public ref class MyClass
{
public:
    [Obsolete]
    void OldMethodHelper();

    [Obsolete]
    void OldMethod();

    void NewMethod();
};

      

In MyClass.cpp

:

void MyClass::OldMethodHelper()
{
    // Some old helper method that called both from within this class and externally.
}

void MyClass::OldMethod()
{
    OldMethodHelper(); // I don't want this call to raise a deprecation warning.
}

void MyClass::NewMethod()
{
    // A new method which replaces the calls to both of the previous methods.
}

      

The code is called like this:

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");

    MyClass m;
    m.OldMethodHelper(); // This should raise a deprecation warning.
    m.OldMethod(); // This should raise a deprecation warning.
    m.NewMethod();

    return 0;
}

      

Edit . I found another SO post that suggested using #pragma warning(disable: 4996)

, but this seems like a bit of a clumsy way to approach me:

    void MyClass::OldMethod()
    {
#pragma warning(push)
#pragma warning(disable: 4996) //4996 for _CRT_SECURE_NO_WARNINGS equivalent
        OldMethodHelper(); // I don't want this call to raise a deprecation warning.
#pragma warning(pop)
    }

      

Edit2 . Made some fixes / clarifications to the sample code.

+3


source to share


1 answer


Without proof, perhaps a macro can help here. Easier to show than to explain:



MyClass.h
---------

#ifndef MYCLASS_DEPRECATE
#define MYCLASS_DEPRECATE [Obsolete]
#endif

class MyClass
{
    MYCLASS_DEPRECATE void OldMethodHelper();

    ...
}

MyClass.cpp
-----------

#define MYCLASS_DEPRECATE
#include "MyClass.h"

// The rest of the code

      

+1


source







All Articles