共用方式為


HOW TO:為 C++ 程式碼加註

若要在 C++ 中為程式碼加註,首先您要加入 SourceAnnotations.h 檔,再使用 vc_attributes 命名空間。

若要在 C++ 中為程式碼加註

  1. 將 #include <CodeAnalysis/SourceAnnotations.h> 檔加入至專案標頭檔中。

  2. 接著,加入 using namespace vc_attributes; 陳述式 (Statement)。

範例

加入 Include 檔案和命名空間之後,請為 C++ 程式碼加註,如下列程式碼所示:

// MyCode.h
#include <CodeAnalysis/SourceAnnotations.h>
using namespace vc_attributes;
class CMyClass
{
public:
       void f ( [Pre ( Valid = Yes )] int *pWidth );
// code ...
};

// MyCode.cpp
#include "MyCode.h"
void CMyClass::f ( [Pre (Valid = Yes)] int pWidth )
{
}

在 C 中,您必須將 SA_ 前置詞當做列舉屬性值使用。 C++ 中的 SA_ 前置詞是選擇項。

請參閱

其他資源

附註屬性