如何:对 C++ 代码进行批注

更新:2007 年 11 月

若要在 C++ 中批注代码,必须首先包括 SourceAnnotations.h 文件,然后使用 vc_attributes 命名空间。

在 C++ 中批注代码

  1. 向项目头文件添加 #include <CodeAnalysis/SourceAnnotations.h> 文件。

  2. 然后,添加 using namespacevc_attributes; 语句。

示例

添加要包括的文件和命名空间后,批注 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_ 前缀是可选的。

请参见

其他资源

批注属性