I have some library code which has some legacy code I'd like to move away from. To do so, I've started marking the outdated methods as deprecated. Where those methods call each other, I get deprecation warnings which I'd rather not see (the new functionality means you just need a single call as less of the internals of the classes workings are exposed).
Is there a way to suppress the deprecation warning for the call from OldMethod
to OldMethodHelper
? ..or a better way to do this altogether?
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's 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.
}
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 post on SO which suggests using #pragma warning(disable: 4996)
is a possibility but it seems like a bit of a clunky way to approach the problem to 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 corrections / clarifications to the code example.