정리

'__declspec(deprecated)'에 해당되는 글 1건

  1. deprecated 설정

deprecated 설정

저장소/VC++
deprecated : 중요도가 떨어져 더 이상 사용되지 않고 앞으로는 사라지게 될(신조어) - by 네이버 영어사전


[Visual C++ Language Reference]

How to use:
__declspec(deprecated) or __declspec(deprecated("do not use"))

(Microsoft specific) With the exceptions noted below, the deprecated declaration offers the same functionality as the deprecated pragma:

  • The deprecated declaration lets you specify particular forms of function overloads as deprecated, whereas the pragma form applies to all overloaded forms of a function name.

  • The deprecated declaration lets you specify a message that will display at compile time. The text of the message can be from a macro.

  • Macros can only be marked as deprecated with the deprecated pragma.

If the compiler encounters the use of a deprecated identifier, a C4996 warning is thrown.


The following sample shows how to mark functions as deprecated, and how to specify a message that will be displayed at compile time, when the deprecated function is used.

// deprecated.cpp
// compile with: /W3
#define MY_TEXT "function is deprecated"
void func1(void) {}
__declspec(deprecated) void func1(int) {}
__declspec(deprecated("** this is a deprecated function **")) void func2(int) {}
__declspec(deprecated(MY_TEXT)) void func3(int) {}

int main() {
   func1();
   func1(1);   // C4996
   func2(1);   // C4996
   func3(1);   // C4996
}

The following sample shows how to mark classes as deprecated, and how to specify a message that will be displayed at compile time, when the deprecated class is used.

// deprecate_class.cpp
// compile with: /W3
struct __declspec(deprecated) X {
   void f(){}
};

struct __declspec(deprecated("** X2 is deprecated **")) X2 {
   void f(){}
};

int main() {
   X x;   // C4996
   X2 x2;   // C4996
}



간단하게 말하자면 앞으로 사용하지 않을, 지원하지 않을, 삭제될 예정인 타입, 클래스, 함수 등을 컴파일 타임에 Warnning으로 처리되어 알리는 역할을 한다. 대충 보니 2003 부터 지원했던 것 같다. 그냥 그러하다.


#pragma deprecated

이런 것도 있는데 귀찮으니 다음에...