I am using the new [[deprecated("message")]] attributes in my code. I have a class that has two constructors, one of which should be marked as deprecated (obviously simplified, and possibly with syntax errors):
class MyClass
{
public:
// good constructor
MyClass(int someNumber): _someNumber(someNumber) {}
[[deprecated("Use MyClass(int) instead")]]
MyClass(const char* someStr): _someNumber(atoi(someStr)) {}
private:
int _someNumber;
}
Visual Studio complains that "attribute 'deprecated("Use MyClass(int) instead")' cannot be applied in this context.
Is there a way to deprecate a constructor in Visual Studio 2015 so that I get a warning if it is used anywhere?
Mark the parameter as deprecated:
MyClass([[deprecated]]const char* someStr){}
Or:
MyClass([[deprecated("Use MyClass(int) instead")]]const char* someStr){}
Or use __declspec(deprecated):
__declspec(deprecated("** Use MyClass(int) instead **"))
MyClass(const char* someStr) : _someNumber(atoi(someStr)) {}
Also depending on your update version (no. 3) you might be experiencing this bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With