Debug 클래스(C++/CLI)

Visual C++ 애플리케이션에서 사용하는 Debug 경우 디버그와 릴리스 빌드 간에 동작이 변경되지 않습니다.

설명

Trace 동작은 디버그 클래스의 동작과 동일하지만 정의되는 TRACE 기호에 따라 달라집니다. 즉, 릴리스 빌드에서 디버그 동작을 방지하려면 추적 관련 코드가 있어야 합니다 #ifdef .

예: 항상 출력 문 실행

설명

다음 샘플에서는 /DDEBUG 또는 /DTRACE를 사용하여 컴파일하는지 여부에 관계없이 항상 출력 문을 실행합니다.

코드

// mcpp_debug_class.cpp
// compile with: /clr
#using <system.dll>
using namespace System::Diagnostics;
using namespace System;

int main() {
   Trace::Listeners->Add( gcnew TextWriterTraceListener( Console::Out ) );
   Trace::AutoFlush = true;
   Trace::Indent();
   Trace::WriteLine( "Entering Main" );
   Console::WriteLine( "Hello World." );
   Trace::WriteLine( "Exiting Main" );
   Trace::Unindent();

   Debug::WriteLine("test");
}

출력

    Entering Main
Hello World.
    Exiting Main
test

예: #ifdef 및 #endif 지시문 사용

설명

예상 동작(즉, 릴리스 빌드에 대해 "테스트" 출력이 인쇄되지 않음)을 얻으려면 and #endif 지시문을 사용해야 #ifdef 합니다. 이전 코드 샘플은 아래 수정되어 이 수정 사항을 보여 줍니다.

코드

// mcpp_debug_class2.cpp
// compile with: /clr
#using <system.dll>
using namespace System::Diagnostics;
using namespace System;

int main() {
   Trace::Listeners->Add( gcnew TextWriterTraceListener( Console::Out ) );
   Trace::AutoFlush = true;
   Trace::Indent();

#ifdef TRACE   // checks for a debug build
   Trace::WriteLine( "Entering Main" );
   Console::WriteLine( "Hello World." );
   Trace::WriteLine( "Exiting Main" );
#endif
   Trace::Unindent();

#ifdef DEBUG   // checks for a debug build
   Debug::WriteLine("test");
#endif   //ends the conditional block
}

참고 항목

C++/CLI를 사용한 .NET 프로그래밍 (Visual C++)