Visual C++ 新增功能(2003 - 2015)Visual C++ What's New 2003 through 2015

本页面包括从 Visual Studio 2003 到 Visual Studio 2015 的所有 Visual C++ 版本的“新增功能”页。This page gathers all the "What's New" pages for all versions of Visual C++ from Visual Studio 2015 back to 2003. 提供这些信息的目的是方便用户从早期版本的 Visual C++ 进行升级。This information is provided as a convenience in case it might be useful when upgrading from earlier versions of Visual C++.

注意:有关 Visual Studio 2017 的信息,请参阅 Visual Studio 2017 中 Visual C++ 的新增功能Visual Studio 2017 中 Visual C++ 的符合性改进Note For information about Visual Studio 2017, see What's new for Visual C++ in Visual Studio 2017 and Conformance Improvements in Visual C++ in Visual Studio 2017.

Visual Studio 2015 中 C++ 的新增功能What's New for C++ in Visual Studio 2015

在 Visual Studio 2015 及更高版本中,对编译器符合性的持续改进有时会改变编译器理解现有源代码的方式。In Visual Studio 2015 and later, ongoing improvements to compiler conformance can sometimes change how the compiler understands your existing source code. 发生这种情况时,可能会在生成过程中遇到新的或不同的错误,甚至以前生成且似乎运行正常的代码也可能出现行为差异。When this happens, you might encounter new or different errors during your build, or even behavioral differences in code that previously built and seemed to run correctly.

幸运的是,这些差异对大部分源代码没有影响或影响极小,而且需要更改源代码或进行其他更改以解决这些差异时,修补程序通常小型且简单。Fortunately, these differences have little or no impact on most of your source code and when source code or other changes are needed to address these differences, fixes are usually small and straight-forward. 我们列出了以前可接受、现在可能需要更改的许多源代码示例(之前)及其修补程序(之后)。We've included many examples of previously-acceptable source code that might need to be changed (before) and the fixes to correct them (after).

虽然这些差异可能会影响源代码或其他生成项目,但其不会影响 Visual C++ 版本更新之间的二进制文件兼容性。Although these differences can affect your source code or other build artifacts, they don't affect binary compatibility between updates to Visual C++ versions. 重大更改是严重性较高的更改,可能会影响二进制文件兼容性,但此类二进制文件兼容性中断问题仅发生在 Visual C++ 的主版本之间。A more-severe kind of change, the breaking change can affect binary compatibility, but these kinds of binary compatibility breaks only occur between major versions of Visual C++. 例如,在 Visual C ++ 2013 和 Visual C ++ 2015 之间。For example, between Visual C++ 2013 and Visual C++ 2015. 有关 Visual C++ 2013 和 Visual C++ 2015 之间的重大更改的详细信息,请参阅 Visual C++ 更改历史记录(2003 - 2015)For information on the breaking changes that occurred between Visual C++ 2013 and Visual C++ 2015, see Visual C++ change history 2003 - 2015.

Visual Studio 2015 的符合性改进Conformance Improvements in Visual Studio 2015

  • /Zc:forScope- option 编译器选项 /Zc:forScope- 已弃用,并且将在将来版本中删除。/Zc:forScope- option The compiler option /Zc:forScope- is deprecated and will be removed in a future release.

     Command line warning  D9035: option 'Zc:forScope-' has been deprecated and will be removed in a future release
    

    以前会经常用到此选项,以便允许非标准代码在点的位置之后使用循环变量,根据标准规范,这些变量本应该在范围之外。The option was usually used in order to allow nonstandard code that uses loop variables after the point where, according to the standard, they should have gone out of scope. 仅当使用 /Za 选项进行编译时才需要,因为没有 /Za,将始终允许在循环结束后使用 for 循环变量。It was only necessary when you are compiling with the /Za option, since without /Za, using a for loop variable after the end of the loop is always allowed. 如果你不关心标准符合性(例如,如果你的代码不是为了移植到其他编译器),你可以关闭 /Za 选项(或将“禁用语言扩展”属性设置为“否”)。If you don't care about standards conformance (for example, if your code isn't meant to portable to other compilers), you could turn off the /Za option (or set the Disable Language Extensions property to No). 如果你确实关心编写可移植且符合标准的代码,则应重写代码,以便通过将此类变量的声明移到循环以外的点使其符合标准。If you do care about writing portable, standards-compliant code, you should rewrite your code so that it conforms to the standard by moving the declaration of such variables to a point outside the loop.

     // zc_forScope.cpp
     // compile with: /Zc:forScope- /Za
     // C2065 expected
     int main() {
        // Uncomment the following line to resolve.
        // int i;
        for (int i =0; i < 1; i++)
           ;
        i = 20;   // i has already gone out of scope under /Za
     }
    
  • /Zg 编译器选项Zg compiler option. /Zg 编译器选项(生成函数原型)不再可用。The /Zg compiler option (Generate Function Prototypes) is no longer available. 此此编译器选项已被弃用。This compiler option was previously deprecated.

  • 你无法再使用 mstest.exe 从命令行运行 C++/CLI 单元测试。You can no longer run unit tests with C++/CLI from the command-line with mstest.exe. 请改用 vstest.console.exeInstead, use vstest.console.exe

  • 可变关键字mutable keyword. 在之前其正确编译的位置,不再允许存在 mutable 存储类说明符。The mutable storage class specifier is no longer allowed in places where previously it compiled without error. 现在,编译器报告错误 C2071(非法存储类)。Now, the compiler gives error C2071 (illegal storage class). 根据标准,可变说明符仅可应用于类数据成员的名称,不能应用于声明为 const 或 static 的名称,也不能应用于引用成员。According to the standard, the mutable specifier can be applied only to names of class data members, and cannot be applied to names declared const or static, and cannot be applied to reference members.

    例如,考虑以下代码:For example, consider the following code:

     struct S {
         mutable int &r;
     };
    

    早期版本的 Visual C++ 编译器接受此代码,但现在编译器则报告以下错误:Previous versions of the Visual C++ compiler accepted this, but now the compiler gives the following error:

     error C2071: 'S::r': illegal storage class
    

    若要修复此错误,只需删除冗余的可变关键字。To fix the error, simply remove the redundant mutable keyword.

  • char_16_t and char32_t 不能再使用 char16_tchar32_t 作为 typedef 中的别名,因为这些类型现在被视为内置。char_16_t and char32_t You can no longer use char16_t or char32_t as aliases in a typedef, because these types are now treated as built-in. 用户和库作者过去通常将 char16_tchar32_t 分别定义为 uint16_tuint32_t 的别名。It was common for users and library authors to define char16_t and char32_t as aliases of uint16_t and uint32_t, respectively.

     #include <cstdint>
    
     typedef uint16_t char16_t; //C2628
     typedef uint32_t char32_t; //C2628
    
     int main(int argc, char* argv[])
     {
     uint16_t x = 1; uint32_t y = 2;
     char16_t a = x;
     char32_t b = y;
     return 0;
     }
    

    若要更新你的代码,请删除 typedef 声明,并重命名与这些名称发生冲突的任何其他标识符。To update your code, remove the typedef declarations and rename any other identifiers that collide with these names.

  • 非类型模板参数 现在会在提供显式模板参数时准确检查包含非类型模板参数的某些代码的类型符合性。Non-type template parameters Certain code that involves non-type template parameters is now correctly checked for type compatibility when you provide explicit template arguments. 例如,在早期版本的 Visual C++ 中正确编译的以下代码。For example, the following code compiled without error in previous versions of Visual C++.

     struct S1
     {
         void f(int);
         void f(int, int);
     };
    
     struct S2
     {
         template <class C, void (C::*Function)(int) const> void f() {}        
     };
    
     void f()
     {
         S2 s2;
         s2.f<S1, &S1::f>();
     }
    

    当前编译器可以准确报告错误,因为模板参数类型不匹配模板参数(该参数是指向 const 成员的指针,但函数为非 const):The current compiler correctly gives an error, because the template parameter type doesn't match the template argument (the parameter is a pointer to a const member, but the function f is non-const):

     error C2893: Failed to specialize function template 'void S2::f(void)'note: With the following template arguments:note: 'C=S1'note: 'Function=S1::f'
    

    若要在代码中修复此错误,请确保你使用的模板自变量类型匹配模板参数声明的类型。To address this error in your code, make sure that the type of the template argument you use matches the declared type of the template parameter.

  • __declspec(align) 编译器不再接受函数上的 __declspec(align)__declspec(align) The compiler no longer accepts __declspec(align) on functions. 以前会始终忽略此项,但现在会产生编译器错误。This was always ignored, but now it produces a compiler error.

     error C3323: 'alignas' and '__declspec(align)' are not allowed on function declarations
    

    若要解决此问题,请从函数声明中删除 __declspec(align)To fix this problem, remove __declspec(align) from the function declaration. 因为它不起作用,将其删除不会更改任何内容。Since it had no effect, removing it does not change anything.

  • 异常处理 有几个对异常处理的更改。Exception handling There are a couple of changes to exception handling. 首先,异常对象必须可复制或可移动。First, exception objects have to be either copyable or movable. Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013 中编译的以下代码却不能在 Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中进行编译:The following code compiled in Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013, but does not compile in Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015:

     struct S {
     public:
         S();
     private:
         S(const S &);
     };
    
     int main()
     {
         throw S(); // error
     }
    

    问题在于,复制构造函数是私有的,因此对象无法像处理异常的标准过程那样进行复制。The problem is that the copy constructor is private, so the object cannot be copied as happens in the normal course of handling an exception. 当复制构造函数为声明的 explicit时,这同样适用。The same applies when the copy constructor is declared explicit.

     struct S {
         S();
         explicit S(const S &);
     };
    
     int main()
     {
         throw S(); // error
     }
    

    若要更新你的代码,请确保异常对象的复制构造函数是公用的且未标记为 explicitTo update your code, make sure that the copy constructor for your exception object is public and not marked explicit.

    通过值捕获异常还要求异常对象可复制。Catching an exception by value also requires the exception object to be copyable. Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013 中编译的以下代码却不能在 Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中进行编译:The following code compiled in Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013, but does not compile in Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015:

     struct B {
     public:
         B();
     private:
         B(const B &);
     };
    
     struct D : public B {
     };
    
     int main()
     {
         try
         {
         }
         catch (D d) // error
         {
         }
     }
    

    可以通过将 catch 的参数类型更改为引用来解决此问题。You can fix this issue by changing the parameter type for the catch to a reference.

     catch(D& d)
     {
     }
    
  • 后跟宏的字符串文本 编译器现在支持用户定义的文本。String literals followed by macros The compiler now supports user defined literals. 因此,宏之前没有任何干预空格的字符串文本被视为用户定义的文本,这可能会产生错误或意外结果。As a consequence, string literals followed by macros without any intervening whitespace are interpreted as user-defined literals, which might produce errors or unexpected results. 例如,在早期的编译器中,成功编译了以下代码:For example, in previous compilers the following code compiled successfully:

     #define _x "there"
     char* func() {
         return "hello"_x;
     }
     int main()
     {
         char * p = func();
         return 0;
     }
    

    编译器将此视为后跟宏的字符串文本“hello”,该宏是展开的“there”,然后两个字符串串联成一个。The compiler interpreted this as a string literal "hello" followed by a macro, which is expanded "there", and then the two string literals were concatenated into one. Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中,编译器将此解释为用户定义的文字,但由于没有定义匹配的用户定义的 _x 文本,它将报告错误。In Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015, the compiler interprets this as a user-defined literal, but since there is no matching user-defined literal _x defined, it gives an error.

     error C3688: invalid literal suffix '_x'; literal operator or literal operator template 'operator ""_x' not found
     note: Did you forget a space between the string literal and the prefix of the following string literal?
    

    若要解决此问题,请在字符串文本和宏之间添加一个空格。To fix this problem, add a space between the string literal and the macro.

  • 相邻字符串文本 与上文类似,由于字符串分析中的相关变化,没有任何空格的相邻字符串文本(或宽或窄的字符字符串文本)被视为 Visaul C++ 早期版本中的单个串联字符串。Adjacent string literals Similarly to the previous, due to related changes in string parsing, adjacent string literals (either wide or narrow character string literals) without any whitespace were interpreted as a single concatenated string in previous releases of Visaul C++. Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中,现在必须在两个字符串之间添加空格。In Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015, you must now add whitespace between the two strings. 例如,必须更改以下代码:For example, the following code must be changed:

     char * str = "abc""def";
    

    只需在两个字符串之间添加空间。Simply add a space in between the two strings.

     char * str = "abc" "def";
    
  • placement new 和 placement delete 对 delete 运算符做出更改以使其符合 C++14 标准。Placement new and delete A change has been made to the delete operator in order to bring it into conformance with C++14 standard. 标准更改的详细信息位于 C++ 调整了大小的释放Details of the standards change can be found at C++ Sized Deallocation. 这些更改将添加采用大小参数的全局 delete 运算符的形式。The changes add a form of the global delete operator that takes a size parameter. 重大更改为,如果你之前使用的是具有相同签名的运算符 delete(以与 placement new 运算符对应),你将收到编译器错误(C2956,在使用 placement new 的点位置出现,因为在代码中的该位置,编译器会尝试标识适当匹配的 delete 运算符)。The breaking change is that if you were previously using an operator delete with the same signature (to correspond with a placement new operator), you will receive a compiler error (C2956, which occurs at the point where the placement new is used, since that's the position in code where the compiler tries to identify an appropriate matching delete operator).

    函数 void operator delete(void *, size_t) 是与 C++11 中的 placement new 函数“void * operator new(size_t, size_t)”对应的 placement delete 运算符。The function void operator delete(void *, size_t) was a placement delete operator corresponding to the placement new function "void * operator new(size_t, size_t)" in C++11. 使用 C++14 调整了大小的释放,此 delete 函数现在是 常用释放函数 (全局 delete 运算符)。With C++14 sized deallocation, this delete function is now a usual deallocation function (global delete operator). 标准要求为,如果使用 placement new 查找相应的 delete 函数和常用释放函数,则程序会出现格式错误。The standard requires that if the use of a placement new looks up a corresponding delete function and finds a usual deallocation function, the program is ill-formed.

    例如,假设你的代码同时定义了 placement new 和 placement delete:For example, suppose your code defines both a placement new and a placement delete:

     void * operator new(std::size_t, std::size_t);
     void operator delete(void*, std::size_t) noexcept;
    

    由于定义的 placement delete 运算符和新的全局调整大小的 delete 运算符之间的函数签名匹配,因此就会出现问题。The problem occurs because of the match in function signatures between a placement delete operator you've defined, and the new global sized delete operator. 考虑是否可以使用任何 placement new 和 placement delete 运算符的其他类型(size_t 除外)。Consider whether you can use a different type other than size_t for any placement new and delete operators. 请注意,size_t typedef 的类型取决于编译器;在 Visual C++ 中,它是一个无符号整型的 typedef。Note that the type of the size_t typedef is compiler-dependent; it is a typedef for unsigned int in Visual C++. 较好的解决办法就是使用如下的枚举类型:A good solution is to use an enumerated type such as this:

     enum class my_type : size_t {};
    

    然后,更改你对 placement new 和 placement delete 的定义,以使用此类型作为第二个参数(而不是 size_t)。Then, change your definition of placement new and delete to use this type as the second argument instead of size_t. 你还需要更新对 placement new 的调用以传递新类型(例如,通过使用 static_cast<my_type> 从整数值转换)并更新 new 和 delete 的定义以强制转换回整数类型。You’ll also need to update the calls to placement new to pass the new type (for example, by using static_cast<my_type> to convert from the integer value) and update the definition of new and delete to cast back to the integer type. 你无需为此使用枚举;具有 size_t 成员的类类型也将起作用。You don’t need to use an enum for this; a class type with a size_t member would also work.

    你还可以将 placement new 全部消除作为备选解决方案。An alternative solution is that you might be able to eliminate the placement new altogether. 如果你的代码使用 placement new 实现内存池,其中位置参数是分配或删除的对象的大小,则调整了大小的释放功能可能适合替换你自定义的内存池代码,且你可以去掉位置函数,仅使用自己两个参数的 delete 运算符(而不是位置函数)。If your code uses placement new to implement a memory pool where the placement argument is the size of the object being allocated or deleted, then sized deallocation feature might be suitable to replace your own custom memory pool code, and you can get rid of the placement functions and just use your own two-argument delete operator instead of the placement functions.

    如果你不想立即更新代码,可以通过使用编译器选项 /Zc:sizedDealloc- 恢复到旧行为。If you don't want to update your code immediately, you can revert to the old behavior by using the compiler option /Zc:sizedDealloc-. 如果使用此选项,则不存在两个参数的 delete 函数,并且也不会导致与 placement delete 运算符发生冲突。If you use this option, the two-argument delete functions don’t exist and won't cause a conflict with your placement delete operator.

  • 联合数据成员Union data members

    联合数据成员不再具有引用类型。Data members of unions can no longer have reference types. 以下代码在 Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013中成功编译,但在 Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中产生错误。The following code compiled successfully in Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013, but produces an error in Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015.

     union U1 {
         const int i;
     };
     union U2 {
        int &i;
     };
     union U3 {
         struct {int &i;};
     };
    

    前面的代码产生以下错误:The preceding code produces the following errors:

     test.cpp(67): error C2625: 'U2::i': illegal union member; type 'int &' is reference type
     test.cpp(70): error C2625: 'U3::i': illegal union member; type 'int &' is reference type
    

    若要解决此问题,请将引用类型更改为指针或值。To address this issue, change reference types either to a pointer or a value. 更改指针类型需要对使用联合字段的代码进行更改。Changing the type to a pointer requires changes in the code that uses the union field. 将代码更改为值将更改存储在联合中的数据,这会影响其他字段,因为联合类型中的字段共享相同的内存。Changing the code to a value would change the data stored in the union, which affects other fields since fields in union types share the same memory. 根据值的大小,它还可能更改联合的大小。Depending on the size of the value, it might also change the size of the union.

  • 匿名联合现在更符合标准。Anonymous unions are now more conformant to the standard. 早期版本的编译器生成了匿名联合的显式构造函数和析构函数。Previous versions of the compiler generated an explicit constructor and destructor for anonymous unions. 这些在 Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中已删除。These are deleted in Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015.

     struct S {
       S();
      };
    
      union {
       struct {
        S s;
       };
      } u; // C2280
    

    前面的代码在 Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中生成以下错误:The preceding code generates the following error in Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015:

     error C2280: '<unnamed-type-u>::<unnamed-type-u>(void)': attempting to reference a deleted function
     note: compiler has generated '<unnamed-type-u>::<unnamed-type-u>' here
    

    若要解决此问题,请提供你对构造函数和/或析构函数的定义。To resolve this issue, provide your own definitions of the constructor and/or destructor.

     struct S {
     // Provide a default constructor by adding an empty function body.
     S() {}
     };
    
     union {
     struct {
     S s;
     };
     } u;
    
  • 具有匿名结构的联合 为了符合标准,已对联合中的匿名结构的成员更改了运行时行为。Unions with anonymous structs In order to conform with the standard, the runtime behavior has changed for members of anonymous structures in unions. 创建此类联合时,将不再隐式调用联合中的匿名结构成员的构造函数。The constructor for anonymous structure members in a union is no longer implicitly called when such a union is created. 此外,联合超出范围时,不再隐式调用联合中的匿名结构成员的析构函数。Also, the destructor for anonymous structure members in a union is no longer implicitly called when the union goes out of scope. 请考虑以下代码,其中联合 U 包含一个匿名结构,此匿名结构包含的成员是一个具有析构函数的命名结构 S。Consider the following code, in which a union U contains an anonymous structure that contains a member which is a named structure S that has a destructor.

     #include <stdio.h>
     struct S {
         S() { printf("Creating S\n"); }
         ~S(){ printf("Destroying S\n"); }
     };
     union U {
         struct {
         S s;
     };
         U() {}
         ~U(){}
     };
    
     void f()
     {
         U u;
         // Destructor implicitly called here.
     }
    
     int main()
     {
         f();
    
         char s[1024];
         printf("Press any key.\n");
         gets_s(s);
         return 0;
     }
    

    Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013 中,创建联合时会调用 S 的构造函数,清理函数 f 的堆栈时会调用 S 的析构函数。In Visual Studio 2013 中的 Visual C++Visual C++ in Visual Studio 2013, the constructor for S is called when the union is created, and the destructor for S is called when the stack for function f is cleaned up. 但在 Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015 中,不会调用构造函数和析构函数。But in Visual Studio 2015 中的 Visual C++Visual C++ in Visual Studio 2015, the constructor and destructor are not called. 编译器会对关于此行为的更改发出警告。The compiler gives a warning about this behavior change.

     warning C4587: 'U::s': behavior change: constructor is no longer implicitly calledwarning C4588: 'U::s': behavior change: destructor is no longer implicitly called
    

    若要还原原始行为,请赋予匿名结构一个名称。To restore the original behavior, give the anonymous structure a name. 无论编译器版本为何,非匿名结构的运行时行为都是相同的。The runtime behavior of non-anonymous structures is the same, regardless of the compiler version.

     #include <stdio.h>
    
     struct S {
         S() { printf("Creating S.\n"); }
         ~S() { printf("Destroying S\n"); }
     };
     union U {
         struct {
             S s;
         } namedStruct;
         U() {}
         ~U() {}
     };
    
     void f()
     {
         U u;
     }
    
     int main()
     {
         f();
    
         char s[1024];
         printf("Press any key.\n");
         gets_s(s);
         return 0;
     }
    

    或者,尝试将构造函数和析构函数代码移到新的函数中,并从联合的构造函数和析构函数添加对这些函数的调用。Alternatively, try moving the constructor and destructor code into new functions, and add calls to these functions from the constructor and destructor for the union.

     #include <stdio.h>
    
     struct S {
         void Create() { printf("Creating S.\n"); }
         void Destroy() { printf("Destroying S\n"); }
     };
     union U {
         struct {
             S s;
         };
         U() { s.Create();  }
         ~U() { s.Destroy(); }
     };
    
     void f()
     {
         U u;
     }
    
     int main()
     {
         f();
    
     char s[1024];
     printf("Press any key.\n");
     gets_s(s);
     return 0;
     }
    
  • 模板解析 对模板的名称解析进行了更改。Template resolution Changes have been made to name resolution for templates. 在 C++ 中,考虑名称解析的候选对象时,可能会出现作为潜在匹配项考虑的一个或多个名称生成无效的模板实例化的情况。In C++, when considering candidates for the resolution of a name, it can be the case that one or more names under consideration as potential matches produces an invalid template instantiation. 这些无效的实例化通常不会导致编译器错误,这被称为 SFINAE(替换失败不是错误)原则。These invalid instantiations do not normally cause compiler errors, a principle which is known as SFINAE (Substitution Failure Is Not An Error).

    现在,如果 SFINAE 要求编译器将类模板专用化进行实例化,则在此过程中发生的任何错误都是编译器错误。Now, if SFINAE requires the compiler to instantiate the specialization of a class template, then any errors that occur during this process are compiler errors. 在早期版本中,编译器会忽略此类错误。In previous versions, the compiler would ignore such errors. 例如,考虑以下代码:For example, consider the following code:

     #include <type_traits>
    
     template<typename T>
     struct S
     {
     S() = default;
     S(const S&);
     S(S&&);
    
     template<typename U, typename = typename std::enable_if<std::is_base_of<T, U>::value>::type>
     S(S<U>&&);
     };
    
     struct D;
    
     void f1()
     {
     S<D> s1;
         S<D> s2(s1);
     }
    
     struct B
     {
     };
    
     struct D : public B
     {
     };
    
     void f2()
     {
     S<D> s1;
         S<D> s2(s1);
     }
    

    如果使用当前编译器进行编译,将得到以下错误:If you compile with the current compiler, you get the following error:

     type_traits(1110): error C2139: 'D': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of'
     ..\t331.cpp(14): note: see declaration of 'D'
     ..\t331.cpp(10): note: see reference to class template instantiation 'std::is_base_of<T,U>' being compiled
             with
             [
                 T=D,
                 U=D
             ]
    

    这是因为在第一次调用 is_base_of 时,尚未定义类“D”。This is because at the point of the first invocation of the is_base_of the class 'D' has not yet been defined.

    在这种情况下,解决方法是在定义类之前,不使用此类类型特征。In this case, the fix is not to use such type traits until the class has been defined. 如果将 D 和 B 的定义移到代码文件的开头,错误将得到解决。If you move the definitions of B and D to the beginning of the code file, the error is resolved. 如果定义位于标头文件中,请检查标头文件的 include 语句的顺序,以确保在使用有问题的模板之前,对任何类定义进行了编译。If the definitions are in header files, check the order of the include statements for the header files to make sure that any class definitions are compiled before the problematic templates are used.

  • 复制构造函数Visual Studio 2013Visual Studio 2013 和 Visual Studio 2015 中,如果该类具有用户定义的移动构造函数,但没有用户定义的复制构造函数,则编译器生成类的复制构造函数。Copy constructors In both Visual Studio 2013Visual Studio 2013 and Visual Studio 2015, the compiler generates a copy constructor for a class if that class has a user-defined move constructor but no user-defined copy constructor. 在 Dev14 中,此隐式生成的复制构造函数也标记为“= delete”。In Dev14, this implicitly generated copy constructor is also marked "= delete".

Visual Studio 2015 Update 1 的符合性改进Conformance Improvements in Visual Studio 2015 Update 1

  • 私有虚拟基类和间接继承 早期版本的编译器允许派生类调用间接派生 private virtual 基类的成员函数。Private virtual base classes and indirect inheritance Previous versions of the compiler allowed a derived class to call member functions of its indirectly-derivedprivate virtual base classes. 这种旧行为不正确,也不符合 C++ 标准。This old behavior was incorrect and does not conform to the C++ standard. 编译器不再接受这种方式编写的代码,因此会发出编译器错误 C2280。The compiler no longer accepts code written in this way and issues compiler error C2280 as a result.

     error C2280: 'void *S3::__delDtor(unsigned int)': attempting to reference a deleted function
    

    示例(之前)Example (before)

     class base
     {
     protected:
         base();
         ~base();
     };
    
     class middle: private virtual base {};class top: public virtual middle {};
    
     void destroy(top *p)
     {
         delete p;  //
     }
    

    示例(之后)Example (after)

     class base;  // as above
    
     class middle: protected virtual base {};
     class top: public virtual middle {};
    
     void destroy(top *p)
     {
         delete p;
     }
    

    -or-

     class base;  // as above
    
     class middle: private virtual base {};
     class top: public virtual middle, private virtual bottom {};
    
     void destroy(top *p)
     {
         delete p;
     }
    
  • 重载的 new 运算符和 delete 运算符 早期版本的编译器允许非成员 operator new 和非成员 operator delete 声明为静态,并在全局命名空间之外的命名空间中声明。Overloaded operator new and operator delete Previous versions of the compiler allowed non-member operator new and non-member operator delete to be declared static, and to be declared in namespaces other than the global namespace. 这种旧行为会引发风险,导致程序无法按按程序员的预期调用 newdelete 运算符实现,从而导致无提示的运行时行为错误。This old behavior created a risk that the program would not call the new or delete operator implementation that the programmer intended, resulting in silent bad runtime behavior. 编译器不再接受这种方式编写的代码,因此会发出编译器错误 C2323。The compiler no longer accepts code written in this way and issues compiler error C2323 instead.

     error C2323: 'operator new': non-member operator new or delete functions may not be declared static or in a namespace other than the global namespace.
    

    示例(之前)Example (before)

     static inline void * __cdecl operator new(size_t cb, const std::nothrow_t&)  // error C2323
    

    示例(之后)Example (after)

     void * __cdecl operator new(size_t cb, const std::nothrow_t&)  // removed 'static inline'
    
    Additionally, although the compiler doesn't give a specific diagnostic, inline operator new is considered ill-formed.
    
  • 对非类类型调用“operator type()”(用户定义的转换) 早期版本的编译器允许以无提示忽略的方式对非类类型调用“operator type()”。Calling 'operator type()' (user-defined conversion) on non-class types Previous versions of the compiler allowed 'operator type()' to be called on non-class types while silently ignoring it. 这种旧行为会导致无提示代码生成错误风险,从而导致不可预知的运行时行为。This old behavior created a risk of silent bad code generation, resulting in unpredictable runtime behavior. 编译器不再接受这种方式编写的代码,因此会发出编译器错误 C2228。The compiler no longer accepts code written in this way and issues compiler error C2228 instead.

     error C2228: left of '.operator type' must have class/struct/union
    

    示例(之前)Example (before)

     typedef int index_t;
    
     void bounds_check(index_t index);
    
     void login(int column)
     {
         bounds_check(column.operator index_t());  // error C2228
     }
    

    示例(之后)Example (after)

     typedef int index_t;
    
     void bounds_check(index_t index);
    
     void login(int column)
     {
          bounds_check(column);  // removed cast to 'index_t', 'index_t' is an alias of 'int'
     }
    
  • 详细的类型说明符中的多余 typename 早期版本的编译器允许详细的类型说明符中出现 typename;用这种方式编写的代码在语义上不正确。Redundant typename in elaborated type specifiers Previous versions of the compiler allowed typename in an elaborated type specifiers; code written in this way is semantically incorrect. 编译器不再接受这种方式编写的代码,因此会发出编译器错误 C3406。The compiler no longer accepts code written in this way and issues compiler error C3406 instead.

     error C3406: 'typename' cannot be used in an elaborated type specifier
    

    示例(之前)Example (before)

     template <typename class T>
     class container;
    

    示例(之后)Example (after)

     template <class T>  // alternatively, could be 'template <typename T>'; 'typename' is not elaborating a type specifier in this case
     class container;
    
  • 初始值设定项列表中数组的类型推断 早期版本的编译器不支持对初始值设定项列表中的数组进行类型推断。Type deduction of arrays from an initializer list Previous versions of the compiler did not support type deduction of arrays from an initializer list. 编译器现在支持这种形式的类型推断,因此调用使用初始值设定项列表的函数模板现在可能会不明确,或者选择一个与以前版本的编译器不同的重载。The compiler now supports this form of type deduction and, as a result, calls to function templates using initializer lists might now be ambiguous or a different overload might be chosen than in previous versions of the compiler. 要解决这些问题,程序现在必须显式指定程序员所需的重载。To resolve these issues, the program must now explicitly specify the overload that the programmer intended.

    当这一新行为导致重载解决方法要考虑与以往候选一样好的其他候选时,调用变得不明确,编译器会发出编译器错误 C2668。When this new behavior causes overload resolution to consider an additional candidate that is equally as good as the historic candidate, the call becomes ambiguous and the compiler issues compiler error C2668 as a result.

     error C2668: 'function' : ambiguous call to overloaded function.
    

    示例 1: 对重载函数的调用不明确(之前)Example 1: Ambiguous call to overloaded function (before)

     // In previous versions of the compiler, code written in this way would unambiguously call f(int, Args...)
     template <typename... Args>
     void f(int, Args...);  //
    
     template <int N, typename... Args>
     void f(const int (&)[N], Args...);
    
     int main()
     {
         // The compiler now considers this call ambiguous, and issues a compiler error
         f({3});  error C2668: 'f' ambiguous call to overloaded function
     }
    

    示例 1: 对重载函数的调用不明确(之后)Example 1: ambiguous call to overloaded function (after)

     template <typename... Args>
     void f(int, Args...);  //
    
     template <int N, typename... Args>
     void f(const int (&)[N], Args...);
    
     int main()
     {
         // To call f(int, Args...) when there is just one expression in the initializer list, remove the braces from it.
         f(3);
     }
    

    这一新行为会导致重载解决方法要考虑比以往候选更适合的其他候选时,调用将明确地解析为新候选,导致程序行为的更改可能与程序员的需要有所不同。When this new behavior causes overload resolution to consider an additional candidate that is a better match than the historic candidate, the call resolves unambiguously to the new candidate, causing a change in program behavior that is probably different than the programmer intended.

    示例 2:重载解决方法的更改(之前)Example 2: change in overload resolution (before)

     // In previous versions of the compiler, code written in this way would unambiguously call f(S, Args...)
     struct S
     {
         int i;
         int j;
     };
    
     template <typename... Args>
     void f(S, Args...);
    
     template <int N, typename... Args>
     void f(const int *&)[N], Args...);
    
     int main()
     {
         // The compiler now resolves this call to f(const int (&)[N], Args...) instead
         f({1, 2});
     }
    

    示例 2:重载解决方法的更改(之后)Example 2: change in overload resolution (after)

     struct S;  // as before
    
     template <typename... Args>
     void f(S, Args...);
    
     template <int N, typename... Args>
     void f(const int *&)[N], Args...);
    
     int main()
     {
         // To call f(S, Args...), perform an explicit cast to S on the initializer list.
         f(S{1, 2});
     }
    
  • switch 语句警告的还原 前一个版本的编译器删除了之前存在的与 switch 语句相关的警告;现在已还原所有这些警告。Restoration of switch statement warnings A Previous version of the compiler removed previously-existing warnings related to switch statements; these warnings have now been restored. 编译器现在将发出还原的警告,并且现在会在包含有问题用例的行中发出与特定用例(包括默认情况下)相关的警告,而不是在 switch 语句的最后一行发出。The compiler now issues the restored warnings, and warnings related to specific cases (including the default case) are now issued on the line containing the offending case, rather than on the last line of the switch statement. 因此,现在发出这些警告的行与过去不同,按照需要使用 #pragma warning(disable:####) 可不再禁止显示以前禁止显示的警告。As a result of now issuing those warnings on different lines than in the past, warnings previously suppressed by using #pragma warning(disable:####) may no longer be suppressed as intended. 要按照需要禁止显示这些警告,可能需要将 #pragma warning(disable:####) 指令移到第一个可能有问题的用例上面的行。To suppress these warnings as intended, it might be necessary to move the #pragma warning(disable:####) directive to a line above the first potentially-offending case. 以下是还原的警告。The following are the restored warnings.

     warning C4060: switch statement contains no 'case' or 'default' labels
    
     warning C4061: enumerator 'bit1' in switch of enum 'flags' is not explicitly handled by a case label
    
     warning C4062: enumerator 'bit1' in switch of enum 'flags' is not handled
    
     warning C4063: case 'bit32' is not a valid value for switch of enum 'flags'
    
     warning C4064: switch of incomplete enum 'flags'
    
     warning C4065: switch statement contains 'default' but no 'case' labels
    
     warning C4808: case 'value' is not a valid value for switch condition of type 'bool'
    
     Warning C4809: switch statement has redundant 'default' label; all possible 'case' labels are given
    

    C4063 示例(之前)Example of C4063 (before)

     class settings
     {
     public:
         enum flags
         {
             bit0 = 0x1,
             bit1 = 0x2,
             ...
         };
         ...
     };
    
     int main()
     {
         auto val = settings::bit1;
    
         switch (val)
         {
         case settings::bit0:
             break;
    
         case settings::bit1:
             break;
    
         case settings::bit0 | settings::bit1:  // warning C4063
             break;
         }
     };
    

    C4063 示例(之后)Example of C4063 (after)

     class settings {...};  // as above
    
     int main()
     {
         // since C++11, use std::underlying_type to determine the underlying type of an enum
         typedef std::underlying_type<settings::flags>::type flags_t;
    
         auto val = settings::bit1;
    
         switch (static_cast<flags_t>(val))
         {
         case settings::bit0:
             break;
    
         case settings::bit1:
             break;
    
         case settings::bit0 | settings::bit1:  // ok
             break;
         }
     };
    

    在其文档中提供了其他还原警告的示例。Examples of the other restored warnings are provided in their documentation.

  • #include:在路径名中使用父目录说明符“..” (只影响 /Wall/WX)#include: use of parent-directory specifier '..' in pathname (only affects /Wall /WX)

    早期版本的编译器没有检测到使用父目录说明符“..”Previous versions of the compiler did not detect the use of the parent-directory specifier '..' (在 #include 指令的路径名中)。in the pathname of #include directives. 以这种方式编写的代码通常用于包含因不正确使用项目相对路径而留在项目外的标头。Code written in this way is usually intended to include headers that exist outside of the project by incorrectly using project-relative paths. 这一旧行为会引发风险,导致编译程序时包含了程序员不需要的源文件来,或这些相对路径不能移植到其他生成环境中。This old behavior created a risk that the program could be compiled by including a different source file than the programmer intended, or that these relative paths would not be portable to other build environments. 编译器现在会检测以这种方式编写的代码并通知程序员,并发出可选编译器警告 C4464(如果已启用)。The compiler now detects and notifies the programmer of code written in this way and issues an optional compiler warning C4464, if enabled.

     warning C4464: relative include path contains '..'
    

    示例(之前)Example (before)

     #include "..\headers\C4426.h"  // emits warning C4464
    

    示例(之后)Example (after)

     #include "C4426.h"  // add absolute path to 'headers\' to your project's include directories
    

    此外,虽然编译器并不会进行具体诊断,但建议不应将父目录说明符“..”用于指定项目的包含目录。Additionally, although the compiler does not give a specific diagnostic, we also recommend that the parent-directory specifier ".." should note be used to specify your project's include directories.

  • #pragma optimize() 超出标头文件的末尾 (只影响 /Wall/WX)#pragma optimize() extends past end of header file (only affects /Wall /WX)

    早期版本的编译器无法检测到对转义翻译单元中包含的标头文件的优化标志设置的更改。Previous versions of the compiler did not detect changes to optimization flag settings that escape a header file included within a translation unit. 编译器现在会检测以这种方式编写的代码并通知程序员,并在有问题的 #include的位置发出可选编译器警告 C4426(如果已启用)。The compiler now detects and notifies the programmer of code written in this way and issues an optional compiler warning C4426 at the location of the offending #include, if enabled. 只有更改与编译器命令行参数设置的优化标志发生冲突时,才发出此警告。This warning is only issued if the changes conflict with the optimization flags set by command-line arguments to the compiler.

     warning C4426: optimization flags changed after including header, may be due to #pragma optimize()
    

    示例(之前)Example (before)

     // C4426.h
     #pragma optimize("g", off)
     ...
     // C4426.h ends
    
     // C4426.cpp
     #include "C4426.h"  // warning C4426
    

    示例(之后)Example (after)

     // C4426.h
     #pragma optimize("g", off)
     ...
     #pragma optimize("", on)  // restores optimization flags set via command-line arguments
     // C4426.h ends
    
     // C4426.cpp
     #include "C4426.h"
    
  • #pragma warning(push)#pragma warning(pop) (只影响 /Wall/WX)Mismatched #pragma warning(push) and #pragma warning(pop) (only affects /Wall /WX)

    早期版本的编译器无法检测到不同源文件中与 #pragma warning(pop) 状态更改配对的 #pragma warning(push) 状态更改,这并不是我们所预期的。Previous versions of the compiler did not detect #pragma warning(push) state changes being paired with #pragma warning(pop) state changes in a different source file, which is rarely intended. 这种旧行为会引发风险,导致程序编译时会启用一组程序员不希望出现的警告,可能会导致无提示的运行时行为错误。This old behavior created a risk that the program would be compiled with a different set of warnings enabled than the programmer intended, possibly resulting in silent bad runtime behavior. 编译器现在能够检测以这种方式编写的代码并通知程序员,并在匹配 #pragma warning(pop) 位置发出可选编译器警告 C5031(如果已启用)。The compiler now detects and notifies the programmer of code written in this way and issues an optional compiler warning C5031 at the location of the matching #pragma warning(pop), if enabled. 此警告包括引用相应 #pragma warning(push) 的位置的注释。This warning includes a note referencing the location of the corresponding #pragma warning(push).

     warning C5031: #pragma warning(pop): likely mismatch, popping warning state pushed in different file
    

    示例(之前)Example (before)

     // C5031_part1.h
     #pragma warning(push)
     #pragma warning(disable:####)
     ...
     // C5031_part1.h ends without #pragma warning(pop)
    
     // C5031_part2.h
     ...
     #pragma warning(pop)  // pops a warning state not pushed in this source file
     ...
     // C5031_part1.h ends
    
     // C5031.cpp
     #include "C5031_part1.h" // leaves #pragma warning(push) 'dangling'
     ...
     #include "C5031_part2.h" // matches 'dangling' #pragma warning(push), resulting in warning C5031
     ...
    

    示例(之后)Example (after)

     // C5031_part1.h
     #pragma warning(push)
     #pragma warning(disable:####)
     ...
     #pragma warning(pop)  // pops the warning state pushed in this source file
     // C5031_part1.h ends without #pragma warning(pop)
    
     // C5031_part2.h
     #pragma warning(push)  // pushes the warning state pushed in this source file
     #pragma warning(disable:####)
     ...
     #pragma warning(pop)
     // C5031_part1.h ends
    
     // C5031.cpp
     #include "C5031_part1.h" // #pragma warning state changes are self-contained and independent of other source files or their #include order.
     ...
     #include "C5031_part2.h"
     ...
    

    虽然不常见,但是有时会故意以这种方式编写代码。Though uncommon, code written in this way is sometimes intentional. 以这种方式编写的代码对于 #include 顺序的更改比较敏感;如果可能,我们建议源代码文件以自包含的方式管理警告状态。Code written in this way is sensitive to changes in #include order; when possible, we recommend that source code files manage warning state in a self-contained way.

  • #pragma warning(push) 不匹配(只影响 /Wall/WX) 早期版本的编译器无法检测到翻译单元末尾出现的不匹配 #pragma warning(push) 状态更改。Unmatched #pragma warning(push) (only affects /Wall /WX) Previous versions of the compiler did not detect unmatched #pragma warning(push) state changes at the end of a translation unit. 编译器现在能够检测以这种方式编写的代码并通知程序员,并在不匹配的 #pragma warning(push) 位置发出可选编译器警告 C5032(如果已启用)。The compiler now detects and notifies the programmer of code written in this way and issues an optional compiler warning C5032 at the location of the unmatched #pragma warning(push), if enabled. 只有翻译单元中没有任何编译错误时,才会发出此警告。This warning is only issued if there are no compilation errors in the translation unit.

     warning C5032: detected #pragma warning(push) with no corresponding #pragma warning(pop)
    

    示例(之前)Example (before)

     // C5032.h
     #pragma warning(push)
     #pragma warning(disable:####)
     ...
     // C5032.h ends without #pragma warning(pop)
    
     // C5032.cpp
     #include "C5032.h"
     ...
     // C5032.cpp ends -- the translation unit is completed without #pragma warning(pop), resulting in warning C5032 on line 1 of C5032.h
    

    示例(之后)Example (after)

     // C5032.h
     #pragma warning(push)
     #pragma warning(disable:####)
     ...
     #pragma warning(pop) // matches #pragma warning (push) on line 1
     // C5032.h ends
    
     // C5032.cpp
     #include "C5032.h"
     ...
     // C5032.cpp ends -- the translation unit is completed without unmatched #pragma warning(push)
    
  • #pragma 警告状态跟踪改进后可能会发出更多警告 早期版本的编译器无法有效跟踪 #pragma 警告状态更改,因而无法发出所有所需的警告。Additional warnings might be issued as a result of improved #pragma warning state tracking Previous versions of the compiler tracked #pragma warning state changes insufficiently well to issue all intended warnings. 这种行为会引发风险,导致在程序不希望的情况下有效禁止显示某些警告。This behavior created a risk that certain warnings would be effectively suppressed in circumstances different than the programmer intended. 编译器现在能够更加可靠地跟踪 #pragma 警告状态,尤其与模板内部的 #pragma 警告状态更改相关,并选择性发出新警告 C5031 和 C5032,旨在帮助程序员找到意外使用 #pragma warning(push)#pragma warning(pop)The compiler now tracks #pragma warning state more robustly -- especially related to #pragma warning state changes inside of templates -- and optionally issues new warnings C5031 and C5032 which are intended to help the programmer locate unintended uses of #pragma warning(push) and #pragma warning(pop).

    由于改进了 #pragma 警告状态更改跟踪,现在可能会发出以前错误地禁止显示的警告或与以前误诊问题的相关警告。As a result of improved #pragma warning state change tracking, warnings formerly incorrectly suppressed or warnings related to issues formerly misdiagnosed might now be issued.

  • 对无法访问代码标识的改进 针对早期版本的编译器进行的 C++ 标准库的更改和内联函数调用能力改进可能会使编译器能够证明某些代码现在无法访问。Improved identification of unreachable code C++ Standard Library changes and improved ability to inline function calls over previous versions of the compiler might allow the compiler to prove that certain code is now unreachable. 这一新行为可能导致新警告并更频繁地发出警告 C4720 实例。This new behavior can result in new and more-frequently issued instances of warning C4720.

     warning C4720: unreachable code
    

    在许多情况下,只有启用优化进行编译时,才会发出此警告,因为优化可能嵌入更多函数调用,消除冗余代码或者能够确定某些代码是否无法访问。In many cases, this warning might only be issued when compiling with optimizations enabled, since optimizations may inline more function calls, eliminate redundant code, or otherwise make it possible to determine that certain code is unreachable. 我们观察到,警告 C4720 的新实例在 try/catch 块中经常发生,尤其是在使用 std::find时。We have observed that new instances of warning C4720 have frequently occurred in try/catch blocks, especially in relation to use of std::find.

    示例(之前)Example (before)

     try
     {
         auto iter = std::find(v.begin(), v.end(), 5);
     }
     catch(...)
     {
         do_something();  // ok
     }
    

    示例(之后)Example (after)

     try
     {
         auto iter = std::find(v.begin(), v.end(), 5);
     }
     catch(...)
     {
         do_something();  // warning C4702: unreachable code
     }
    

Visual Studio 2015 Update 2 的符合性改进Conformance Improvements in Visual Studio 2015 Update 2

  • 可能会因对表达式 SFINAE 的部分支持而发出其他警告和错误 由于缺少对表达式 SFINAE 的支持,编译器的早期版本无法分析 decltype 说明符中特定类型的表达式。Additional warnings and errors might be issued as a result of partial support for expression SFINAE Previous versions of the compiler did not parse certain kinds of expressions inside decltype specifiers due to lack of support for expression SFINAE. 这种旧行为不正确,也不符合 C++ 标准。This old behavior was incorrect and does not conform to the C++ standard. 由于持续的符合性改进,此编译器现已可分析这些表达式,并能为表达式 SFINAE 提供部分支持。The compiler now parses these expressions and has partial support for expression SFINAE due to ongoing conformance improvements. 因此,此编译器现在可发出在编译器的早期版本无法分析的表达式中找到的警告和错误。As a result, the compiler now issues warnings and errors found in expressions that previous versions of the compiler did not parse.

    此新行为分析包含尚未声明类型的 decltype 表达式时,将导致编译器发出编译器错误 C2039。When this new behavior parses a decltype expression that includes a type that has not yet been declared, the compiler issues compiler error C2039 as a result.

     error C2039: 'type': is not a member of '`global namespace''
    

    示例 1:使用未声明的类型(之前)Example 1: use of an undeclared type (before)

     struct s1
     {
       template <typename T>
       auto f() -> decltype(s2<T>::type::f());  // error C2039
    
       template<typename>
       struct s2 {};
     }
    

    示例 1(之后)Example 1 (after)

     struct s1
     {
       template <typename>  // forward declare s2struct s2;
    
       template <typename T>
       auto f() -> decltype(s2<T>::type::f());
    
       template<typename>
       struct s2 {};
     }
    

    此新行为分析 decltype 表达式时(该表达式缺少将依赖名称指定为类型所必须使用的关键字 typename),编译器将发出编译器警告 C4346 和编译器错误 C2923。When this new behavior parses a decltype expression that is missing a necessary use of the typename keyword to specify that a dependent name is a type, the compiler issues compiler warning C4346 together with compiler error C2923.

     warning C4346: 'S2<T>::Type': dependent name is not a type
    
     error C2923: 's1': 'S2<T>::Type' is not a valid template type argument for parameter 'T'
    

    示例 2:依赖名称不是类型(之前)Example 2: dependent name is not a type (before)

     template <typename T>
     struct s1
     {
       typedef T type;
     };
    
     template <typename T>
     struct s2
     {
       typedef T type;
     };
    
     template <typename T>
     T declval();
    
     struct s
     {
       template <typename T>
       auto f(T t) -> decltype(t(declval<S1<S2<T>::type>::type>()));  // warning C4346, error C2923
     };
    

    示例 2(之后)Example 2 (after)

     template <typename T> struct s1 {...};  // as above
     template <typename T> struct s2 {...};  // as above
    
     template <typename T>
     T declval();
    
     struct s
     {
       template <typename T>
       auto f(T t) -> decltype(t(declval<S1<typename S2<T>::type>::type>()));
     };
    
  • volatile 成员变量将防止出现隐式定义的构造函数和赋值运算符 编译器的早期版本允许具有 volatile 成员变量的类自动生成默认复制/移动构造函数和默认复制/移动赋值运算符。volatile member variables prevent implicitly defined constructors and assignment operators Previous versions of the compiler allowed a class that has volatile member variables to have default copy/move constructors and default copy/move assignment operators automatically generated. 这种旧行为不正确,也不符合 C++ 标准。This old behavior was incorrect and does not conform to the C++ standard. 编译器现在认为拥有可变成员变量的类具有非常用构造函数和赋值运算符,这将防止自动生成这些运算符的默认实现。The compiler now considers a class that has volatile member variables to have non-trivial construction and assignment operators which prevents default implementations of these operators from being automatically generated. 当此类为某一联合(或类中的匿名联合)的成员时,会将联合(或包含匿名联合的类)的复制/移动构造函数和复制/移动赋值运算符的隐式定义为已删除。When such a class is a member of a union (or an anonymous union inside of a class), the copy/move constructors and copy/move assignment operators of the union (or the class containing the unonymous union) will be implicitly defined as deleted. 尝试构造或复制联合(或包含匿名联合的类)而不显式定义它们是错误的,将导致编译器发出编译器错误 C2280。Attempting to construct or copy the union (or class containing the anonymous union) without explicitly defining them is an error and the compiler issues compiler error C2280 as a result.

     error C2280: 'B::B(const B &)': attempting to reference a deleted function
    

    示例(之前)Example (before)

     struct A
     {
       volatile int i;
       volatile int j;
     };
    
     extern A* pa;
    
     struct B
     {
       union
       {
         A a;
         int i;
       };
     };
    
     B b1 {*pa};
     B b2 (b1);  // error C2280
    

    示例(之后)Example (after)

     struct A
     {
       int i;int j;
     };
    
     extern volatile A* pa;
    
     A getA()  // returns an A instance copied from contents of pa
     {
       A a;
       a.i = pa->i;
       a.j = pa->j;
       return a;
     }
    
     struct B;  // as above
    
     B b1 {GetA()};
     B b2 (b1);  // error C2280
    
  • 静态成员函数不支持 cv 限定符。Static member functions do not support cv-qualifiers. Visual C++ 2015 的早期版本允许静态成员函数具有 cv 限定符。Previous versions of Visual C++ 2015 allowed static member functions to have cv-qualifiers. 此行为是由于 Visual C++ 2015 和 Visual C++ 2015 Update 1 中的回归而导致的;Visual C++ 2013 和 Visual C++ 的早期版本拒绝接受以这种方式编写的代码。This behavior is due to a regression in Visual C++ 2015 and Visual C++ 2015 Update 1; Visual C++ 2013 and previous versions of Visual C++ reject code written in this way. Visual C++ 2015 和 Visual C++ 2015 Update 1 的行为不正确且不符合 C++ 标准。The behavior of Visual C++ 2015 and Visual C++ 2015 Update 1 is incorrect and does not conform to the C++ standard. Visual Studio 2015 Update 2 拒绝接受以这种方式编写的代码,并改为发出编译器错误 C2511。Visual Studio 2015 Update 2 rejects code written in this way and issues compiler error C2511 instead.

     error C2511: 'void A::func(void) const': overloaded member function not found in 'A'
    

    示例(之前)Example (before)

     struct A
     {
       static void func();
     };
    
     void A::func() const {}  // C2511
    

    示例(之后)Example (after)

     struct A
     {
       static void func();
     };
    
     void A::func() {}  // removed const
    
  • WinRT 代码中不允许枚举的前向声明(仅影响 /ZW) 为 Windows 运行时 (WinRT) 编译的代码不允许前向声明 enum 类型,这与使用 /clr 编译器开关为 .Net Framework 编译托管 C++ 代码时相似。Forward declaration of enum is not allowed in WinRT code (affects /ZW only) Code compiled for the Windows Runtime (WinRT) doesn't allow enum types to be forward declared, similarly to when managed C++ code is compiled for the .Net Framework using the /clr compiler switch. 此行为可确保枚举大小始终为已知,并可将其正确映射到 WinRT 类型系统。This behavior is ensures that the size of an enumeration is always known and can be correctly projected to the WinRT type system. 编译器将拒绝接受以这种方式编写的代码,并发出编译器错误 C2599 和编译器错误 C3197。The compiler rejects code written in this way and issues compiler error C2599 together with compiler error C3197.

     error C2599: 'CustomEnum': the forward declaration of a WinRT enum is not allowed
    
     error C3197: 'public': can only be used in definitions
    

    示例(之前)Example (before)

     namespace A {
       public enum class CustomEnum: int32;  // forward declaration; error C2599, error C3197
     }
    
     namespace A {
       public enum class CustomEnum: int32
       {
         Value1
       };
     }
    
     public ref class Component sealed
     {
     public:
       CustomEnum f()
       {
         return CustomEnum::Value1;
       }
     };
    

    示例(之后)Example (after)

               // forward declaration of CustomEnum removed
    
     namespace A {
       public enum class CustomEnum: int32
       {
         Value1
       };
     }
    
     public ref class Component sealed
     {
     public:
       CustomEnum f()
       {
         return CustomEnum::Value1;
       }
     };
    
  • 重载的非成员 new 运算符和 delete 运算符可能不是以内联方式声明的(默认开启等级 1 (/W1)) 当以内联方式声明非成员 new 运算符和 delete 运算符函数时,编译器的早期版本不会发出警告。Overloaded non-member operator new and operator delete may not be declared inline (Level 1 (/W1) on-by-default) Previous versions of the compiler do not issue a warning when non-member operator new and operator delete functions are declared inline. 以这种方式编写的代码格式不正确(无需诊断),并且可能由于不匹配的 new 和 delete 运算符(尤其是与调整了大小的释放共同使用时)而导致难以诊断的内存问题。Code written in this way is ill-formed (no diagnostic required) and can cause memory issues resulting from mismatched new and delete operators (especially when used together with sized deallocation) that can be difficult to diagnose. 编译器现将发出编译器警告 C4595 以帮助识别以这种方式编写的代码。The compiler now issues compiler warning C4595 to help identify code written in this way.

     warning C4595: 'operator new': non-member operator new or delete functions may not be declared inline
    

    示例(之前)Example (before)

               inline void* operator new(size_t sz)  // warning C4595
     {
       ...
     }
    

    示例(之后)Example (after)

               void* operator new(size_t sz)  // removed inline
     {
       ...
     }
    

    修复以这种方式编写的代码可能需要将运算符定义从头文件移动到相应的源文件中。Fixing code that's written in this way might require that the operator definitions be moved out of a header file and into a corresponding source file.

Visual Studio 2015 Update 3 的符合性改进Conformance Improvements in Visual Studio 2015 Update 3

  • 现在,std::is_convertable 可以检测自我赋值(标准库) 以前版本的 std::is_convertable type-trait 在其复制构造函数被删除或私有时,无法正确检测类类型的自我赋值。std::is_convertable now detects self-assignment (standard library) Previous versions of the std::is_convertable type-trait did not correctly detect self-assignment of a class type when its copy constructor is deleted or private. 现在,当应用于具有已删除或私有复制构造函数的类类型时,std::is_convertable<>::value 已正确设置为 falseNow, std::is_convertable<>::value is correctly set to false when applied to a class type with a deleted or private copy constructor.

    没有与此更改相关联的编译器诊断。There is no compiler diagnostic associated with this change.

    示例Example

     #include <type_traits>
    
     class X1
     {
     public:
         X1(const X1&) = delete;
     };
    
     class X2
     {
     private:
         X2(const X2&);
     };
    
     static_assert(std::is_convertible<X1&, X1>::value, "BOOM");static_assert(std::is_convertible<X2&, X2>::value, "BOOM");
    

    在以前版本的 Visual C++ 中,此示例底部的静态断言可传递,因为 std::is_convertable<>::value 错误地设置为 trueIn previous versions of Visual C++, the static assertions at the bottom of this example pass because std::is_convertable<>::value was incorrectly set to true. 现在,std::is_convertable<>::value 正确设置为 false,使静态断言失败。Now, std::is_convertable<>::value is correctly set to false, causing the static assertions to fail.

  • 默认设置或已删除的日常复制和移动构造函数遵从访问说明符 对于默认设置或已删除的日常复制和移动构造函数的访问说明符,早期版本的编译器在允许调用之前不进行检查。Defaulted or deleted trivial copy and move constructors respect access specifiers Previous versions of the compiler did not check the access specifier of defaulted or deleted trivial copy and move constructors before allowing them to be called. 这种旧行为不正确,也不符合 C++ 标准。This old behavior was incorrect and does not conform to the C++ standard. 在某些情况下,这种旧行为会导致无提示代码生成错误风险,从而导致不可预知的运行时行为。In some cases, this old behavior created a risk of silent bad code generation, resulting in unpredictable runtime behavior. 现在,编译器检查默认设置或已删除的日常复制和移动构造函数的访问说明符,以确定是否能调用它,如果不能,则发出编译器警告 C2248。The compiler now checks the access specifier of defaulted or deleted trivial copy and move constructors to determine whether it can be called, and if not, issues compiler warning C2248 as a result.

     error C2248: 'S::S' cannot access private member declared in class 'S'
    

    示例(之前)Example (before)

     class S {
     public:
        S() = default;
     private:
         S(const S&) = default;
     };
    
     void f(S);  // pass S by value
    
     int main()
     {
         S s;
         f(s);  // error C2248, can't invoke private copy constructor
     }
    

    示例(之后)Example (after)

     class S {
     public:
        S() = default;
     private:
         S(const S&) = default;
     };
    
     void f(const S&);  // pass S by reference
    
     int main()
     {
         S s;
         f(s);
     }
    
  • 弃用属性化 ATL 代码支持(默认开启等级 1 (/W1)) 早期版本的编译器支持属性化 ATL 代码。Deprecation of attributed ATL code support (Level 1 (/W1) on-by-default) Previous versions of the compiler supported attributed ATL code. 由于下一阶段将删除从 Visual C++ 2008 开始的属性化 ATL 代码支持,所以已弃用属性化 ATL 代码。As the next phase of removing support for attributed ATL code that began in Visual C++ 2008, attributed ATL code has been deprecated. 编译器现将发出编译器警告 C4467 以帮助识别这类已弃用的代码。The compiler now issues compiler warning C4467 to help identify this kind of deprecated code.

     warning C4467: Usage of ATL attributes is deprecated
    

    若要在编译器删除支持之前继续使用属性化 ATL 代码,可以通过将 /Wv:18/wd4467 命令行参数传递给编译器或在源代码中添加 #pragma warning(disable:4467) 来禁用此警告。If you want to continue using attributed ATL code until support is removed from the compiler, you can disable this warning by passing the /Wv:18 or /wd4467 command line arguments to the compiler, or by adding #pragma warning(disable:4467) in your source code.

    示例 1(之前)Example 1 (before)

               [uuid("594382D9-44B0-461A-8DE3-E06A3E73C5EB")]
     class A {};
    

    示例 1(之后)Example 1 (after)

     __declspec(uuid("594382D9-44B0-461A-8DE3-E06A3E73C5EB")) A {};
    

    有时需要创建 IDL 文件以避免使用已弃用的 ATL 属性,如以下示例代码所示Sometimes you might need or want to create an IDL file to avoid the use deprecated ATL attributes, as in the example code below

    示例 2(之前)Example 2 (before)

     [emitidl];
     [module(name="Foo")];
    
     [object, local, uuid("9e66a290-4365-11d2-a997-00c04fa37ddb")]
     __interface ICustom {
         HRESULT Custom([in] long l, [out, retval] long *pLong);
         [local] HRESULT CustomLocal([in] long l, [out, retval] long *pLong);
     };
    
     [coclass, appobject, uuid("9e66a294-4365-11d2-a997-00c04fa37ddb")]
     class CFoo : public ICustom
     {
         // ...
     };
    

    首先,创建 *.idl 文件;vc140.idl 生成的文件可用于获取包含接口和注释的 *.idl文件。First, create the *.idl file; the vc140.idl generated file can be used to obtain an *.idl file containing the interfaces and annotations.

    然后,将 MIDL 步骤添加到生成中以确保生成 C++ 接口定义。Next, add a MIDL step to your build to make sure that the C++ interface definitions are generated.

    示例 2 IDL(之后)Example 2 IDL (after)

     import "docobj.idl";
    
     [
         object,local,uuid(9e66a290-4365-11d2-a997-00c04fa37ddb)
     ]
    
     interface ICustom : IUnknown {
         HRESULT  Custom([in] long l, [out,retval] long *pLong);
         [local] HRESULT  CustomLocal([in] long l, [out,retval] long *pLong);
     };
    
     [ version(1.0), uuid(29079a2c-5f3f-3325-99a1-3ec9c40988bb) ]
     library Foo
     {
         importlib("stdole2.tlb");
         importlib("olepro32.dll");
             [
                 version(1.0),
                 appobject,uuid(9e66a294-4365-11d2-a997-00c04fa37ddb)
             ]
    
         coclass CFoo {
             interface ICustom;
         };
     }
    

    然后,在实现文件中直接使用 ATL,如以下示例代码所示。Then, use ATL directly in the implementation file, as in the example code below.

    示例 2 实现(之后)Example 2 Implementation (after)

     #include <idl.header.h>
     #include <atlbase.h>
    
     class ATL_NO_VTABLE CFooImpl :
         public ICustom,
         public ATL::CComObjectRootEx<CComMultiThreadModel>
     {
     public:
         BEGIN_COM_MAP(CFooImpl)
         COM_INTERFACE_ENTRY(ICustom)
         END_COM_MAP()
     };
    
  • 预编译标头 (PCH) 文件和不匹配的 #include 指令(仅影响 /Wall /WX)使用预编译标头 (PCH) 文件时,以前版本的编译器接受 -Yc-Yu 编译之间的源文件中不匹配的 #include 指令。Precompiled header (PCH) files and mismatched #include directives (only affects /Wall /WX) Previous versions of the compiler accepted mismatched #include directives in source files between -Yc and -Yu compilations when using precompiled header (PCH) files. 编译器不再接受以这种方式编写的代码。Code written in this way is no longer accepted by the compiler. 使用 PCH 文件时,编译器现将发出编译器警告 CC4598 以帮助识别不匹配的 #include 指令。The compiler now issues compiler warning CC4598 to help identify mismatched #include directives when using PCH files.

     warning C4598: 'b.h': included header file specified for Ycc.h at position 2 does not match Yuc.h at that position
    

    示例(之前):Example (before):

    X.cpp (-Ycc.h)X.cpp (-Ycc.h)

     #include "a.h"
     #include "b.h"
     #include "c.h"
    

    Z.cpp (-Yuc.h)Z.cpp (-Yuc.h)

     #include "b.h"
     #include "a.h"  // mismatched order relative to X.cpp
     #include "c.h"
    

    示例(之后)Example (after)

    X.cpp (-Ycc.h)X.cpp (-Ycc.h)

     #include "a.h"
     #include "b.h"
     #include "c.h"
    

    Z.cpp (-Yuc.h)Z.cpp (-Yuc.h)

     #include "a.h"
     #include "b.h" // matched order relative to X.cpp
     #include "c.h"
    
  • 预编译标头 (PCH) 文件和不匹配的包含目录(仅影响 /Wall /WX) 使用预编译标头 (PCH) 文件时,对于 -Yc-Yu 编译之间的编译器,以前版本的编译器接受不匹配的包含目录 (-I) 命令行参数。Precompiled header (PCH) files and mismatched include directories (only affects /Wall /WX) Previous versions of the compiler accepted mismatched include directory (-I) command line arguments to the compiler between -Yc and -Yu compilations when using precompiled header (PCH) files. 编译器不再接受以这种方式编写的代码。Code written in this way is no longer accepted by the compiler. 使用 PCH 文件时,编译器现将发出编译器警告 CC4599 以帮助识别不匹配的包含目录 (-I) 命令行参数。The compiler now issues compiler warning CC4599 to help identify mismatched include directory (-I) command line arguments when using PCH files.

     warning C4599: '-I..' : specified for Ycc.h at position 1 does not match Yuc.h at that position
    

    示例(之前)Example (before)

     cl /c /Wall /Ycc.h -I.. X.cpp
     cl /c /Wall /Yuc.h Z.cpp
    

    示例(之后)Example (after)

     cl /c /Wall /Ycc.h -I.. X.cpp
     cl /c /Wall /Yuc.h -I.. Z.cpp
    

Visual Studio 2013 中 C++ 的新增功能What's New for C++ in Visual Studio 2013

改进的 ISO C/C++ 标准支持Improved ISO C/C++ Standards Support

编译器Compiler

Microsoft Visual C++ 编译器支持以下 ISO C++11 语言功能:The Microsoft Visual C++ compiler supports these ISO C++11 language features:

  • 函数模板的默认模板参数。Default template arguments for function templates.
  • 委托构造函数Delegating constructors
  • 显式转换运算符。Explicit conversion operators.
  • 初始值设定项列表和统一初始化。Initializer lists and uniform initialization.
  • 原始字符串文本。Raw string literals.
  • 可变参数模板。Variadic templates.
  • 别名模板。Alias templates.
  • 已删除的函数。Deleted functions.
  • 非静态数据成员初始值设定项 (NSDMI)。Non-static data member initializers (NSDMIs).
  • 默认的函数。Defaulted functions. *
  • 支持以下 ISO C99 语言功能:Supports these ISO C99 language features:
  • _Bool_Bool
  • 复合文本。Compound literals.
  • 指定的初始值设定项。Designated initializers.
  • 组合带有代码的声明。Mixing declarations with code.
  • 字符串文本转换为可修改的值可通过使用新编译器选项 /Zc:strictStrings 禁用。String literal conversion to modifiable values can be disallowed by using the new compiler option /Zc:strictStrings. 在 C++98 中,已弃用从字符串文本转换至 char*(和将宽字符串文本转换为 wchar_t*)。In C++98, conversion from string literals to char* (and wide string literals to wchar_t*) was deprecated. 在 C++11 中,已将转换完全移除。In C++11, the conversion was removed entirely. 虽然编译器可以严格遵循该标准,但提供了 /Zc:strictStrings 选项,以便控制转换。Although the compiler could strictly conform to the standard, instead it provides the /Zc:strictStrings option so that you can control conversion. 默认情况下,该选项是关闭的。By default, the option is off. 注意,当您在调试模式下使用此选项,STL 将无法编译。Note that when you are using this option in debug mode, the STL will not compile.
  • rvalue/lvalue 引用转换。rvalue/lvalue Reference Casts. 通过 rvalue 引用,C++11 可清晰地区分 lvalue 和 rvalue。With rvalue references, C++11 can clearly distinguish between lvalues and rvalues. 过去,在特定强制转换方案中,编译器不提供此功能。Previously, the compiler did not provide this in specific casting scenarios. 添加了新编译器选项 /Zc:rvalueCast,以使编译器与 C++ 语言的工作文件相符(请参阅第 5.4 节,[expr.cast]/1)。A new compiler option, /Zc:rvalueCast, has been added to make the compiler conformant with the C++ Language Working Paper(see section 5.4, [expr.cast]/1). 未指定选项时,该默认行为与 Visual Studio 2012 中的相同。The default behavior when this option is not specified is the same as in Visual Studio 2012.
    • 请注意:默认函数不支持使用 =default 逐一请求成员移动构造函数和赋值运算符。Note: For defaulted functions, using =default to request memberwise move constructors and move assignment operators is not supported.

C99 库C99 Libraries

为下列标头中缺少的函数添加了声明和实现:math.h、ctype.h、wctype.h、stdio.h、stdlib.h 和 wchar.h。Declarations and implementations are added for missing functions in these headers: math.h, ctype.h, wctype.h, stdio.h, stdlib.h, and wchar.h. 同样添加的还有新标头 complex.h、stdbool.h、fenv.h 和 inttypes.h,以及这些新标头中声明的所有函数的实现。Also added are the new headers complex.h, stdbool.h, fenv.h, and inttypes.h, and implementations for all the functions declared in them. 新增了一些 C++ 包装器标头(ccomplex、cfenv、cinttypes 和 ctgmath)并更新了许多其他标头(ccomplex、cctype、clocale、cmath、cstdint、cstdio、cstring、cwchar 和 cwctype)。There are new C++ wrapper headers (ccomplex, cfenv, cinttypes, ctgmath) and a number of others are updated (ccomplex, cctype, clocale, cmath, cstdint, cstdio, cstring, cwchar, and cwctype).

标准模板库Standard Template Library

支持 C++11 显式转换运算符、初始值设定项列表、范围枚举和 variadic 模板。Support for the C++11 explicit conversion operators, initializer lists, scoped enums, and variadic templates. 现在所有容器都支持 C++11 细化的元素要求。All containers now support the C++11 fine-grained element requirements. 支持这些 C++14 功能:Support for these C++14 features:

  • “透明运算符函子”less<>、greater<>、plus<>、multiplies<> 等等。"Transparent operator functors" less<>, greater<>, plus<>, multiplies<>, and so on.
  • make_unique(args...) 和 make_unique <T[]>(n)make_unique(args...) and make_unique<T[]>(n)
  • cbegin()/cend()、rbegin()/rend() 和 crbegin()/crend() 非成员函数。cbegin()/cend(), rbegin()/rend(), and crbegin()/crend() non-member functions.
  • <atomic> 接收多个性能增强。<atomic> received numerous performance enhancements.
  • <type_traits> 接收主要稳定性和代码修复。<type_traits> received major stabilization and code fixes.

重大更改Breaking Changes

对 ISO C/C++ 标准的改进支持可能需要对现有代码进行更改,从而符合 C++11 并在 Visual Studio 2013 的 Visual C++ 中正确编译。This improved support for ISO C/C++ standards may require changes to existing code so that it conforms to C++11 and compiles correctly in Visual C++ in Visual Studio 2013.

Visual C++ 库增强功能Visual C++ Library Enhancements

  • 添加了 C++ REST SDK。C++ REST SDK is added. 它具有 REST 服务的现代 C++ 实现。It has a modern C++ implementation of REST services.
  • C++ AMP 纹理支持已改进。C++ AMP Texture support is enhanced. 现在包括对 mipmap 和新采样模式的支持。It now includes support for mipmaps and new sampling modes.
  • PPL 任务支持多个计划技术和异步调试。PPL tasks support multiple scheduling technologies and asynchronous debugging. 采用新 API,可为常规结果和异常条件创建 PPL 任务。New APIs enable the creation of PPL tasks for both normal results and exception conditions.

C++ 应用程序性能C++ Application Performance

  • 自动向量化现在可以识别和优化更多 C++ 模式,加快代码运行速度。Auto-Vectorizer now recognizes and optimizes more C++ patterns to make your code run faster.
  • ARM 平台和 Atom 微型体系结构代码质量增强功能。ARM platform and Atom micro-architecture code quality improvements.
  • 添加了 __vectorcall 调用约定。__vectorcall calling convention is added. 使用 __vectorcall 调用约定来传递向量类型参数,从而使用向量寄存器。Pass vector type arguments by using the __vectorcall calling convention to use vector registers.
  • 新链接器选项。New Linker Options. 使用 /Gw(编译器)和 /Gy(汇编程序)开关,优化链接器以生成更精简的二进制代码。The /Gw (compiler) and /Gy (assembler) switches enable linker optimizations to produce leaner binaries.
  • C++ AMP 共享内存支持,可减少或消除 CPU 和 GPU 间的数据复制。C++ AMP shared memory support to reduce or eliminate data copying between CPU and GPU.

按配置优化选项 (PGO) 增强Profile Guided Optimization (PGO) enhancements

  • 通过使用 PGO 实现已优化的应用程序工作集的缩减,从而提高性能。Performance improvements from a reduction in the working set of apps that are optimized by using PGO.
  • 用于 Windows 运行时应用开发的新 PGO。New PGO for Windows Runtime app development.

Windows 运行时应用开发支持Windows Runtime App Development Support

  • 支持值结构中的装箱类型。Support For Boxed Types In Value structs. 现在可以使用可以为空的字段(例如与 IBox<int>^ 相对的 int)来定义值类型。这意味着字段可以具有值,或者与 nullptr 相等。You can now define value types by using fields that can be null—for example, IBox<int>^ as opposed to int. This means that the fields can either have a value, or be equal to nullptr.
  • 更丰富的异常信息。Richer Exception Information. C++/CX 支持能够在整个应用程序二进制接口 (ABI) 中获取和传播各种异常信息的新 Windows 错误模型;这包括调用堆栈和自定义消息字符串。C++/CX supports the new Windows error model that enables the capture and propagation of rich exception information across the application binary interface (ABI); this includes call stacks and custom message strings.
  • Object::ToString() 现在为虚拟。Object::ToString() Is Now Virtual. 现在可以重写用户定义的 Windows 运行时引用类型中的 ToString。You can now override ToString in user-defined Windows Runtime ref types.
  • 支持已弃用的 API。Support For Deprecated APIs. 公共 Windows 运行时 API 现在可标记为已弃用并可收到一条自定义消息,此消息显示为生成警告并可提供迁移指南。Public Windows Runtime APIs can now be marked as deprecated and given a custom message that appears as a build warning and can provide migration guidance.
  • 调试器改进。Debugger Improvements. 支持本机/JavaScript 互操作调试、Windows 运行时异常诊断和异步代码调试(windows 运行时和 PPL)。Support for native/JavaScript interop debugging, Windows Runtime exception diagnosis, and async code debugging (both Windows Runtime and PPL).
    • 请注意:除本节中介绍的 C++ 特定功能和增强功能外,Visual Studio 中的其他增强功能还可帮助你编写更好的 Windows 运行时应用。Note: In addition to the C++-specific features and enhancements that are described in this section, other enhancements in Visual Studio also can help you write better Windows Runtime apps.

诊断增强功能Diagnostics Enhancements

  • 调试器改进。Debugger Improvements. 支持异步调试和“仅我的代码”调试。Support for async debugging and Just My Code debugging.
  • 代码分析类别。Code Analysis Categories. 现在可以查看代码分析器的分类输出,帮助您找到并修复代码缺陷。You can now view categorized output from the Code Analyzer to help you find and fix code defects.
  • XAML 诊断。XAML Diagnostics. 现在可以诊断 XAML 中的 UI 响应和电池使用情况问题。You can now diagnose UI-responsiveness and battery-usage issues in your XAML.
  • 图像和 GPU 调试改进。Graphics and GPU Debugging Improvements.
  • 在实际设备上远程捕获和重放。Remote capture and playback on real devices.
  • 同步 C++ AMP 和 CPU 调试。Simultaneous C++ AMP and CPU debugging.
  • 改进的 C++ AMP 运行时诊断。Improved C++ AMP runtime diagnostics.
  • HLSL 计算着色器跟踪调试。HLSL Compute shader trace debugging.

三维图形增强功能3-D Graphics Enhancements

  • 图像内容管线支持预乘 alpha DDS 格式。Image Content Pipeline support for pre-multiplied alpha DDS format.
  • 图像编辑器使用内部预乘 alpha 进行呈现,从而避免呈现暗的光晕等项目。Image Editor uses internally pre-multiplied alpha for rendering, and thereby avoids rendering artifacts such as dark halos.
  • 图像和模型编辑器。Image and Model Editors. 图像编辑器和模型编辑器的“着色器设计器”现在支持用户定义的筛选器创建。User-defined filter creation is now supported in Shader Designer in Image Editor and Model Editor.

IDE 与工作效率IDE and Productivity

已改进的代码格式设置Improved Code Formatting. 您可以将多个格式设置应用于 C++ 代码。You can apply more formatting settings to your C++ code. 使用这些设置,您可以控制大括号和关键字、缩进、间距和自动换行的新行位置。By using these settings, you can control new-line placement of braces and keywords, indentation, spacing, and line wrapping. 当完成语句和块并且将代码粘贴到文件中时,代码将自动进行格式化。Code is automatically formatted when you complete statements and blocks, and when you paste code into a file.

大括号完成。Brace Completion. 现在,C++ 代码会自动完成对应于这些开始字符的结束字符:C++ code now auto-completes the closing characters that correspond to these opening characters:

  • {(大括号){ (curly brace)
  • [(方括号)[ (square bracket)
  • ((括号)( (parentheses)
  • '(单引号)' (single quote)
  • "(双引号)" (double quote)

附加 C++ 自动完成功能。Additional C++ Auto-completion Features.

  • 添加用于类类型的分号。Adds semicolon for class types.
  • 完成对原始字符串文本使用括号。Completes parentheses for raw string literals.
  • 完成多行注释 (/* */)Completes multi-line comments (/* */)

查找所有引用在后台引用显示出文本匹配列表后自动对其进行解析和筛选。Find All References now automatically resolves and filters references in the background after it displays the list of textual matches.

基于上下文的成员列表筛选。Context-Based Member List Filtering. 无法访问的成员已从 IntelliSense 成员列表中筛选出来。Inaccessible members are filtered out of the IntelliSense member lists. 例如,私有成员不会在成员列表中显示,除非您修改了实现此类型的代码。For example, private members are not displayed in the member list unless you are modifying the code that implements the type. 当成员列表中处于打开状态时,您可以按 Ctrl+J 移除筛选的一个级别(仅适用于当前成员列表窗口)。While the member list is open, you can press Ctrl+J to remove one level of filtering (applies only to the current member list window). 可以再次按 Ctrl+J 移除文本筛选和显示每个成员。You can press Ctrl+J again to remove the textual filtering and show every member.

参数帮助滚动。Parameter Help Scrolling. 参数帮助工具提示中显示的函数签名现在将根据实际输入参数的数量而改变,而不是只显示一个随机的签名且不根据当前上下文更新。The displayed function signature in the parameter-help tooltip now changes based on the number of parameters you've actually typed, rather than just showing an arbitrary signature and not updating it based on the current context. 函数显示在嵌套函数上时,参数也会适当地帮助函数。Parameter help also functions correctly when it's displayed on nested functions.

切换标题/代码文件。Toggle Header/Code File. 现在,通过使用快捷菜单或键盘快捷方式上的命令,可以在标题及其相应代码文件之间切换。You can now toggle between a header and its corresponding code file by using a command on the shortcut menu, or a keyboard shortcut.

可调整大小的 C++ 项目属性窗口。Resizable C++ Project Properties Window

在 C++/CX 和 C++/CLI 中自动生成事件处理程序代码。Auto-generation of Event Handler Code in C++/CX and C++/CLI. 在键入代码向 C++/CX 或 C++/CLI 代码文件中添加事件处理程序时,编辑器可以自动生成委托实例和事件处理程序定义。When you are typing code to add an event handler in a C++/CX or C++/CLI code file, the editor can automatically generate the delegate instance and event-handler definition. 可以自动生成事件处理程序代码时,会显示工具提示窗口。A tooltip window appears when event-handler code can be auto-generated.

DPI 识别增强功能。DPI Awareness Enhancement. 现在,针对应用程序清单文件的 DPI 识别设置支持“每个高 DPI 识别监视器”的设置。The DPI Awareness setting for application manifest files now supports the "Per Monitor High DPI Aware" setting.

更快的配置切换。Faster Configuration Switching. 对于大型应用程序,切换配置(尤其是后续切换操作)将更快速地执行。For large applications, switching configurations—especially subsequent switching operations—execute much more quickly.

生成时效。Build Time Efficiency. 许多优化和多核使用率使生成更加快速,对于大型项目来说尤为如此。Numerous optimizations and multi-core utilization make builds faster, especially for large projects. 引用了 C++ WinMD 的 C++ 应用程序的增量生成也更加快速。Incremental builds for C++ applications that have references to C++ WinMD are also much faster.

Visual Studio 2012 中 C++ 的新增功能What's New for C++ in Visual Studio 2012

改进的 C++11 标准支持Improved C++11 Standards Support

标准模板库Standard Template Library

  • 对新 STL 标头的支持:<atomic>、<chrono>、<condition_variable>、<filesystem>、<future>、<mutex>、<ratio> 和 <thread>。Support for new STL headers: <atomic>, <chrono>, <condition_variable>, <filesystem>, <future>, <mutex>, <ratio>, and <thread>.
  • 为了优化内存资源的使用,现在减小了容器。To optimize memory resource usage, containers are now smaller. 例如,在具有默认设置的 x86 发布模式下,std::vector 从 Visual Studio 2010 中的 16 字节缩小为 Visual Studio 2012 中的 12 字节,此外 std::map 也从 Visual Studio 2010 中的 16 字节缩小为 Visual Studio 2012 中的 8 字节。For example, in x86 release mode with default settings, std::vector has shrunk from 16 bytes in Visual Studio 2010 to 12 bytes in Visual Studio 2012, and std::map has shrunk from 16 bytes in Visual Studio 2010 to 8 bytes in Visual Studio 2012.
  • 作为 C++ 11 标准的一个可选项,SCARY 迭代器也得到了实现。As permitted but not required by the C++11 Standard, SCARY iterators have been implemented.

其他 C + + 11 增强功能Other C++11 Enhancements

  • 基于范围的 for 循环。Range-based for loops. 可编写以 for ( for-range-declaration : expression ) 形式使用数组、STL 容器和 Windows 运行时集合的更可靠循环。You can write more robust loops that work with arrays, STL containers, and Windows Runtime collections in the form for ( for-range-declaration : expression ). 这是核心语言支持的一部分。This is part of the Core Language support.
  • 无状态 lambda(即以空的 lambda 引导 [] 为开头并且不捕获本地变量的代码块)现在可以根据需要以 C++11 标准隐式转换为函数指针。Stateless lambdas, which are blocks of code that begin with an empty lambda introducer [] and capture no local variables, are now implicitly convertible to function pointers as required by the C++11 Standard.
  • 区分范围的枚举支持。Scoped enumerations support. 现在支持 C++ 枚举类 enum-key。The C++ enum class enum-key is now supported. 下面的代码示范了现在的 enum-key 与以前的枚举行为的不同之处。The following code demonstrates how this enum-key differs from previous enum behavior.

    enum class Element { Hydrogen, Helium, Lithium, Beryllium };
    void func1(Element e);
    func1(Hydrogen); // error C2065: 'Hydrogen' : undeclared identifier
    func1(Element::Helium); // OK
    

Windows 运行时应用开发支持Windows Runtime App Development Support

  • 基于本机 XAML 的 UI 模型Native XAML-based UI model. 可将新的基于本机 XAML 的 UI 模型用于 Windows 运行时应用。For Windows Runtime apps, you can use the new native XAML-based UI model.
  • Visual C++ 组件扩展Visual C++ Component Extensions. 这些扩展减少了 Windows 运行时对象的使用,是 Windows 运行时应用不可缺少的部分。These extensions simplify consumption of Windows Runtime objects, which are a necessary part of Windows Runtime apps. 有关详细信息,请参阅使用 C++ 的 Windows 运行时应用产品指南Visual C++ 语言参考 (C++/CX)For more information, see Roadmap for Windows Runtime apps using C++ and Visual C++ language reference (C++/CX)
  • DirectX 游戏DirectX games. 可以利用 Windows 运行时应用的新的 DirectX 支持来开发有趣的游戏。You can develop engaging games by using the new DirectX support for Windows Runtime apps.
  • XAML/DirectX 交互XAML/DirectX interop. 使用 XAML 和 DirectX 的 Windows 运行时应用现可有效进行交互。Windows Runtime apps that use both XAML and DirectX now interoperate efficiently.
  • Windows 运行时组件 DLL 的开发Windows Runtime Component DLL development. 组件 DLL 的开发使 Windows 运行时环境能够扩展。Component DLL development makes the Windows Runtime environment extensible.

编译器和链接器Compiler and Linker

  • 自动向量化Auto-vectorizer. 编译器会分析代码中的循环,如果可能,还会发出使用向量寄存器的指令和显示在所有新式处理器上的指令。The compiler analyzes loops in your code and, where possible, emits instructions that use the vector registers and instructions that are present in all modern processors. 这使循环运行得更快。This makes the loops run faster. (处理器指令被称为 SSE,即流式处理 SIMD 扩展)。(The processor instructions are known as SSE, for Streaming SIMD Extensions). 此项优化自动应用,无需启用或请求。You do not have to enable or request this optimization because it is applied automatically.
  • 自动并行化程序Auto-parallelizer. 编译器可以分析编码中的循环并发出指令,向多个核心或处理器分散计算。The compiler can analyze loops in your code and emit instructions that spread the calculations across multiple cores or processors. 这能让循环运行得更快。This can make the loops run faster. 此项优化不会自动启用,必须进行请求。You must request this optimization because it is not enabled by default. 在许多情况下,这都有助于在想并行化的循环之前将 #pragma 循环 (hint_parallel(N)) 包含在你的代码中。In many cases, it helps to include a #pragma loop(hint_parallel(N)) in your code immediately before the loops that you want parallelized.
  • 自动向量化和自动并行化可以共同协作以便向多个核心分散计算,并且每个核心上的代码都使用该核心的向量寄存器。The auto-vectorizer and auto-parallelizer can work together so that calculations are spread across multiple cores and the code on each core uses its vector registers.

Visual Studio 2012 Update 1 中的新功能New in Visual Studio 2012 Update 1

在生成 C++ 代码时锁定 Windows XP。Target Windows XP when you build your C++ code. 可以使用 Visual C++ 编译器和库以锁定 Windows XP 和 Windows Server 2003。You can use the Visual C++ compiler and libraries to target Windows XP and Windows Server 2003.

并行编程的支持Parallel Programming Support

C++ Accelerated Massive Parallelism (AMP)C++ Accelerated Massive Parallelism (AMP)

C++ AMP 利用数据并行硬件(通常是离散图形卡上的 GPU)加快 C++ 代码的执行。C++ AMP accelerates the execution of your C++ code by taking advantage of the data-parallel hardware that's ordinarily present as a GPU on a discrete graphics card. C++ AMP 编程模型包括多维数组、索引、内存传输、平铺和数学函数库。The C++ AMP programming model includes multidimensional arrays, indexing, memory transfer, tiling, and a mathematical function library. 通过使用 C++ AMP 语言扩展和编译器限制,可以控制数据在 CPU 和 GPU 之间来回移动的方式。By using C++ AMP language extensions and compiler restrictions, you can control how data is moved from the CPU to the GPU and back.

调试。Debugging. 使用 C++ AMP 锁定 GPU 的应用的调试体验就像其他 C++ 应用的调试一样。The debugging experience for apps that use C++ AMP to target the GPU is just like debugging for other C++ apps. 这包含之前提到的新的并行调试补充内容。This includes the new parallel debugging additions that were mentioned earlier.

分析。Profiling. 现在对基于 C++ AMP 的 GPU 活动和其他基于 Direct3D 的编程模型提供分析支持。There is now profiling support for GPU activity that's based on C++ AMP and other Direct3D-based programming models.

并行编程的常规增强功能General Parallel Programming Enhancements

随着硬件移至多内核和很多内核的结构体系,开发人员可以不再依赖于单内核日益增长的时钟速度。With hardware moving to multi-core and many-core architectures, developers can no longer rely on ever-increasing clock speeds from single-cores. 并发运行时中的并行编程支持使开发人员可以利用这些新的体系结构。The parallel programming support in the Concurrency Runtime enables developers to take advantage of these new architectures. Visual Studio 2010 中引入了像并行模式库这样功能强大的 C++ 并行化库,还有其他功能可以用于利用通过准确精细的数据流管道实现的并发。In Visual Studio 2010, powerful C++ parallelization libraries such as the Parallel Patterns Library were introduced, together with features to take advantage of concurrency by expressing sophisticated dataflow pipelines. 在 Visual Studio 2012 中将这些库进行了扩展以在并行模式上提供更好的性能、更强的控制力以及更丰富的支持,这也是开发人员最需要的。In Visual Studio 2012, these libraries have been extended to provide better performance, more control, and richer support for the parallel patterns that developers need most. 现在产品涵盖以下内容:The breadth of the offering now includes:

  • 丰富的基于任务的编程模型,支持异步和延续。A rich task-based programming model that supports asynchrony and continuations.
  • 支持分叉-联结并行性(parallel_for、具有相关性的 parallel_for、parallel_for_each、parallel_sort、parallel_reduce 以及 parallel_transform)的并行算法。Parallel Algorithms , which support fork-join parallelism (parallel_for, parallel_for with affinity, parallel_for_each, parallel_sort, parallel_reduce, parallel_transform).
  • 并发安全容器,提供线程安全版本的 std 数据结构(例如 priority_queue、queue、vector 和 map)。Concurrency-safe containers, which provide thread-safe versions of std data structures such as priority_queue, queue, vector, and map.
  • 异步代理库,开发人员可以将其用于表达自然分散至并发单元的数据流管道。The Asynchronous Agents Library, which developers can use to express dataflow pipelines that naturally decompose into concurrent units.
  • 可自定义的计划程序和资源管理器,便于将此列表中的模式平滑组合。A customizable scheduler and resource manager to facilitate the smooth composition of the patterns in this list.
并行调试的常规增强功能General Parallel Debugging Enhancements

除了并行任务窗口和并行堆栈窗口以外,Visual Studio 2012 还提供了新的 并行监视窗口,以便跨所有线程和进程检查表达式的值,以及对结果进行排序和筛选。In addition to the Parallel Tasks window and Parallel Stacks window, Visual Studio 2012 offers a new Parallel Watch window so that you can examine the values of an expression across all threads and processes, and perform sorting and filtering on the result. 也可使用可视化工具来扩展窗口,并可利用跨所有工具窗口的全新多进程支持。You can also use your own visualizers to extend the window, and you can take advantage of the new multi-process support across all tool windows.

IDEIDE

Visual Studio 模板支持。Visual Studio Templates support. 现在可以使用 Visual Studio 模板技术创建 C++ 项目和项模板。You can now use the Visual Studio Templates technology to author C++ project and item templates.

异步解决方案加载。Asynchronous Solution Load. 项目现在异步加载(解决方案的关键部分优先加载),从而提供工作效率。Projects are now loaded asynchronously—the key parts of the solution first—so that you can start working faster.

用于远程调试的自动部署。Automated deployment for remote debugging. Visual C++ 中简化了用于远程调试的文件部署。Deployment of files for remote debugging in Visual C++ has been simplified. 项目上下文菜单上的“部署”选项自动将调试配置属性中指定的文件复制到远程计算机。The Deploy option on the project context menu automatically copies to the remote computer the files that are specified in the debugging configuration properties. 不再需要手动将文件复制到远程计算机了。Copying files manually to the remote computer is no longer required.

C++/CLI IntelliSense。C++/CLI IntelliSense. C++/CLI 现在完全支持 IntelliSense。C++/CLI now has full IntelliSense support. 像快速信息、参数帮助、列表成员和自动完成这样的 IntelliSense 功能现在适用于 C++/CLI。IntelliSense features such as Quick Info, Parameter Help, List Members, and Auto Completion now work for C++/CLI. 此外,本文档中列出的其他 IntelliSense 和 IDE 增强也适用于 C++/CLI。In addition, the other IntelliSense and IDE enhancements listed in this document also work for C++/CLI.

更丰富的 IntelliSense 工具提示。Richer IntelliSense Tooltips. C++ IntelliSense 快速信息工具提示现在显示更丰富的 XML 文档注释样式信息。C++ IntelliSense Quick Info tooltips now show richer XML documentation comments style information. 如果使用库中具有 XML 文档注释的 API(例如 C++ AMP),除声明以外,IntelliSense 工具提示还会显示更多信息。If you are using an API from a library—for example, C++ AMP—that has XML documentation comments, then the IntelliSense tooltip shows more information than just the declaration. 此外,如果你的代码具有 XML 文档注释,IntelliSense 工具提示将显示更丰富的信息。Also, if your code has the XML documentation comments, IntelliSense tooltips will show the richer information.

C++ 代码构造。C++ Code Constructs. 主干代码可用于 switch、if-else、for 循环以及列表成员下拉列表中的其他基本代码构造。Skeleton code is available for switch, if-else, for loop, and other basic code constructs, in the List Members drop-down list. 从列表中选择一部分代码插入到你的代码中,然后填写需要的逻辑。Select a piece of code from the list to insert it into your code and then fill in the required logic. 还可以创建自己的自定义代码片段,以便在编辑器中使用。You can also create your own custom pieces of code for use in the editor.

列表成员的增强功能。List Members Enhancements. 在代码编辑器中键入代码时,列表成员下拉列表将自动显示。The List Members drop-down list appears automatically as you type code into the code editor. 结果是筛选过的,所以只会显示与你的类型相关的成员。Results are filtered, so that only relevant members are displayed as you type. 你可以控制列表成员采用的筛选逻辑,要实现此操作,请在“文本编辑器”>“C/C++”>“高级”下的“选项”对话框中操作。You can control the kind of filtering logic that's used by the Member List—in the Options dialog box under Text Editor, C/C++, Advanced.

语义着色。Semantic Colorization. 现在默认对类型、枚举、宏和其他 C++ 标记进行着色。Types, enumerations, macros, and other C++ tokens now have colorization by default.

引用突出显示。Reference Highlighting. 选择一个符号现在将在当前文件中突出显示该符号的所有实例。Selecting a symbol now highlights all instances of the symbol in the current file. 按 Ctrl+Shift+向上键或 Ctrl+Shift+向下键可以在突出显示的引用之间移动。Press Ctrl+Shift+Up Arrow or Ctrl+Shift+Down Arrow to move among the highlighted references. 可以在“文本编辑器”>“C/C++”>“高级”下的“选项”对话框中关闭此功能。You can turn this feature off in the Options dialog box, under Text Editor, C/C++, Advanced.

应用程序生命周期管理 工具Application Lifecycle Management Tools

静态代码分析Static Code Analysis

已更新 C++ 的静态代码分析,以提供更丰富的错误上下文信息、更多分析规则以及更好的分析结果。Static analysis for C++ has been updated to provide richer error context information, more analysis rules, and better analysis results. 在新的代码分析窗口,可按关键字、项目以及严重性来筛选消息。In the new Code Analysis window, you can filter messages by keyword, project, and severity. 当在窗口中选择一条消息时,代码编辑器会突出显示触发该消息的代码行。When you select a message in the window, the line in the code where the message was triggered is highlighted in the code editor. 对于某些 C++ 警告,消息会列出源行,显示导致该警告的执行路径;并突出显示采用该特定路径决策点和理由。For certain C++ warnings, the message lists source lines that show the execution path that leads to the warning; decision points and the reasons for taking that specific path are highlighted. Visual Studio 2012 的大部分版本都包含代码分析。Code analysis is included in most editions of Visual Studio 2012. Professional 版、Premium 版和 Ultimate 版中包含了所有规则。In the Professional, Premium, and Ultimate editions, all rules are included. Windows 8 和 Windows Phone 的 Express 版中只包括最关键的警告。In the Express editions for Windows 8 and Windows Phone, just the most critical warnings are included. Express 网页版中不包括代码分析。Code analysis is not included in the Express edition for Web. 下面是代码分析的一些其他增强:Here are some other code analysis enhancements:

  • 新的并发警告可确保在多线程 C/C++ 程序中使用正确的锁定方式,帮助规避并发 Bug。New concurrency warnings help you avoid concurrency bugs by making sure that you are using the correct locking disciplines in multithreaded C/C++ programs. 分析器检测潜在的争用条件、锁定顺序反转、调用方/被调用方锁定协定冲突、不匹配的同步操作和其他并发 Bug。The analyzer detects potential race conditions, lock order inversions, caller/callee locking contract violations, mismatched synchronization operations, and other concurrency bugs.
  • 你可以通过使用规则集指定想应用于代码分析的 C++ 规则。You can specify the C++ rules that you want to apply to code analysis runs by using rule sets.
  • 在代码分析窗口,你可以将取消显示所选警告的杂注插入到源代码中。In the Code Analysis window, you can insert into the source code a pragma that suppresses a selected warning.
  • 通过使用新版的 Microsoft 源代码注释语言 (SAL) 描述函数使用参数的方式、关于参数做出的假设以及对完成结果的保证,可以增强静态代码分析的准确性和完整性。You can enhance the accuracy and completeness of static code analysis by using the new version of the Microsoft source-code annotation language (SAL) to describe how a function uses its parameters, the assumptions that it makes about them, and the guarantees that it makes when it finishes.
  • 支持 64 位 C++ 项目。Support for 64bit C++ projects.

已更新的单元测试框架Updated Unit Test Framework

可使用 Visual Studio 中新的 C++ 单元测试框架编写 C++ 单元测试。Use the new C++ unit test framework in Visual Studio to write C++ unit tests. 可通过在“新建项目”对话框的“Visual C++ 类别”下找到 C++ 单元测试项目模板,将新的单元测试项目添加到现有 C++ 解决方案。Add a new unit test project to your existing C++ solution by locating the C++ Unit Test Project template under the Visual C++ category in the New Project dialog box. 开始在生成的 TEST_METHOD 代码(在 Unittest1.cpp 文件中存根)中编写你的单元测试。Start writing your unit tests in the generated TEST_METHOD code stub in the Unittest1.cpp file. 编写测试代码时,生成解决方案。When the test code is written, build the solution. 若要运行测试,请从“视图”>“其他窗口”>“单元测试管理器”打开“单元测试资源管理器”窗口,然后在所需测试用例的快捷菜单上选择“运行所选测试”。When you want to run the tests, open a Unit Test Explorer window by choosing View, Other Windows, Unit Test Explorer, and then, on the shortcut menu for the test case you want, choose Run selected test. 测试运行完成以后,可以在同一窗口查看结果和其他堆栈跟踪信息。After the test run finishes, you can view test results and additional stack trace information in the same window.

体系结构依赖项关系图Architecture Dependency Graphs

为了更好地理解代码,可以对二进制、类、命名空间和解决方案中的包含文件生成依赖项关系图。To understand your code better, you can now generate dependency graphs for the binary, class, namespace, and include files in a solution. 在菜单栏上,选择体系结构、生成依赖项关系图,然后为解决方案或包含文件生成依赖项关系图。On the menu bar, choose Architecture, Generate Dependency Graph, and then For Solution or For Include File to generate a dependency graph. 生成关系图后,可以展开各个节点进行浏览,还可以在节点间移动来了解依赖关系,并可通过在节点的快捷菜单上选择“查看内容”来浏览源代码。When the graph generation is complete, you can explore it by expanding each node, learn dependency relationships by moving between nodes, and browse source code by choosing View Content on the shortcut menu for a node. 若要对包含文件生成依赖项关系图,请在 *.cpp 源代码文件或 *.h 头文件的快捷菜单上选择“生成包含文件的关系图”。To generate a dependency graph for include files, on the shortcut menu for a *.cpp source code file or *.h header file, choose Generate Graph of Include Files.

体系结构资源管理器Architecture Explorer

使用体系结构资源管理器,可以浏览 C++ 解决方案、项目或文件中的资产。By using the Architecture Explorer, you can explore the assets in your C++ solution, projects, or files. 在菜单栏上,选择体系结构、窗口、体系结构管理器。On the menu bar, choose Architecture, Windows, Architecture Explorer. 可以选择一个感兴趣的节点,例如“类视图”。You can select a node you are interested in, for example, Class View. 这时工具窗口的右侧会展开一个命名空间列表。In this case, the right side of the tool window is expanded with a list of namespaces. 如果选择一个命名空间,会出现一个新列,显示此命名空间中的类、结构和枚举列表。If you select a namespace, a new column shows a list of the classes, structs, and enums in this namespace. 你可以继续浏览这些资产,也可以返回最左侧的那一列开始另一项查询。You can continue to explore these assets, or go back to the column on the far left to start another query. 查看如何使用体系结构资源管理器查找代码。See Find Code with Architecture Explorer.

代码覆盖率Code Coverage

已更新代码覆盖率,在运行时动态检测二进制。Code coverage has been updated to dynamically instrument binaries at runtime. 这降低了配置开销,提升了性能。This lowers the configuration overhead and provides better performance. 你还可以从 C++ 应用的单元测试收集代码覆盖率数据。You can also collect code-coverage data from unit tests for C++ apps. 如果已创建 C++ 单元测试,可以使用测试单元资源管理器来查看解决方案中的测试。When you have created C++ unit tests, you can use Unit Test Explorer to discover tests in your solution. 若要运行单元测试并为它们收集代码覆盖率数据,请在单元测试资源管理器中选择“分析代码覆盖率”。To run the unit tests and collect code coverage data for them, in Unit Test Explorer, choose Analyze Code Coverage. 你可以在“代码覆盖率结果”窗口(在菜单栏上,选择“测试”>“窗口”>“代码覆盖率结果”)中检查代码覆盖率结果。You can examine the code coverage results in the Code Coverage Results window—on the menu bar, choose Test, Windows, Code Coverage Results.

Visual Studio 2010 中 C++ 的新增功能What's New for C++ in Visual Studio 2010

C++ 编译器和链接器C++ Compiler and Linker

auto 关键字。auto Keyword. auto 关键字有了新的用途。The auto keyword has a new purpose. 使用 auto 关键字的默认含义声明一种变量,该变量的类型是从变量声明中的初始化表达式推导出来的。Use the default meaning of the auto keyword to declare a variable whose type is deduced from the initialization expression in the declaration of the variable. 通过 /Zc:auto 编译器选项,可调用新版或旧版的 auto 关键字的含义。The /Zc:auto compiler option invokes either the new or the previous meaning of the auto keyword.

decltype 类型说明符。decltype Type Specifier. decltype 类型说明符返回指定表达式的类型。The decltype type specifier returns the type of a specified expression. 结合使用 decltype 类型说明符和 auto 关键字可声明复杂的或仅为编译器所知的类型。Use the decltype type specifier in combination with the auto keyword to declare a type that is either complex or known only to the compiler. 例如,将这个组合用于声明返回类型取决于其模板自变量类型的模板函数。For example, use the combination to declare a template function whose return type depends on the types of its template arguments. 或者声明调用其他函数且返回被调用函数类型的模板函数。Or, declare a template function that calls another function, and then returns the return type of the called function.

Lambda 表达式。Lambda Expressions. Lambda 函数有函数体但没有名称。Lambda functions have a function body but no name. lambda 函数兼具函数指针和函数对象的最佳特性。Lambda functions combine the best characteristics of function pointers and function objects. 将 lambda 函数本身用作模板函数参数而不是函数对象,或者将其与 auto 关键字组合使用,可以声明类型为 lambda 的变量。Use a lambda function by itself, as a template function parameter instead of a function object, or together with the auto keyword to declare a variable whose type is a lambda.

Rvalue 引用。Rvalue Reference. Rvalue 引用声明符 (&&) 声明对 rvalue 的引用。The rvalue reference declarator (&&) declares a reference to an rvalue. 通过 rvalue 引用,可以使用更多语义和完美转移编写出更有效的构造函数、函数和模板。An rvalue reference lets you use move semantics and perfect forwarding to write more efficient constructors, functions, and templates.

static_assert 声明。static_assert Declaration. static_assert 声明在编译时测试软件断言,这与在运行时进行测试的其他断言机制不同。A static_assert declaration tests a software assertion at compile time, unlike other assertion mechanisms that test at run time. 如果断言失败,则编译将失败,并且会发出特定的错误消息。If the assertion fails, the compilation fails and a specified error message is issued.

nullptr 和 __nullptr 关键字。nullptr and __nullptr Keywords. 通过 Visual C++ 编译器,可以对本机代码或托管代码使用 nullptr 关键字。The Visual C++ compiler lets you use the nullptr keyword with native code or with managed code. nullptr 关键字指示对象句柄、内部指针或本机指针类型不指向对象。The nullptr keyword indicates that an object handle, interior pointer, or native pointer type does not point to an object. 如果使用 /clr 编译器选项,编译器会将 nullptr 解释为托管代码;如果不使用 /clr 选项,则解释为本机代码。The compiler interprets nullptr to be managed code when you use the /clr compiler option, and native code when you do not use the /clr option. Microsoft 特定的 __nullptr 关键字与 nullptr 的含义相同,但前者仅适用于本机代码。The Microsoft-specific __nullptr keyword has the same meaning as nullptr, but it applies to native code only. 如果使用 /clr 编译器选项编译本机 C/C++ 代码,则编译器无法确定 nullptr 关键字是本机项还是托管项。If you compile native C/C++ code by using the /clr compiler option, the compiler cannot determine whether the nullptr keyword is a native or a managed term. 若要使编译器清楚地了解你的意图,请使用 nullptr 关键字指定托管项,使用 __nullptr 指定本机项。To make your intention clear to the compiler, use the nullptr keyword to specify the managed term, and __nullptr to specify the native term.

/Zc: trigraphs 编译器选项。/Zc:trigraphs Compiler Option. 默认情况下,禁用对三元组的支持。By default, support for trigraphs is disabled. 使用 /Zc: trigraphs 编译器选项以启用三元祖支持。Use the /Zc:trigraphs compiler option to enable trigraphs support. 三元祖由两个连续的问号 (??) 及后跟的唯一的第三个字符组成。A trigraph consists of two consecutive question marks (??) followed by a unique third character. 编译器将三元组替换为相应的标点字符。The compiler replaces a trigraph with the corresponding punctuation character. 例如,编译器会将三元祖 ??= 替换为字符 #(数字字符)。For example, the compiler replaces the ??= trigraph with the # (number sign) character. 对于使用的字符集未包含某些标点字符的 C 源文件,可在其中使用三元组。Use trigraphs in C source files that use a character set that does not contain certain punctuation characters.

新的按配置优化选项。New Profile-Guided Optimization Option. PogoSafeMode 是一个新的按配置优化选项,使用此选项可以指定在优化应用程序时使用安全模式还是快速模式。PogoSafeMode is a new profile-guided optimization option that lets you specify whether to use safe mode or fast mode when you optimize your application. 安全模式是线程安全的,但比快速模式的运行速度慢。Safe mode is thread-safe, but it is slower than fast mode. 快速模式是默认行为。Fast mode is the default behavior.

新的公共语言运行时 (CLR) 选项/clr:nostdlib。New Common Language Runtime (CLR) Option /clr:nostdlib. 为 /clr(公共语言运行时编译)新增了一个选项。A new option is added for /clr (Common Language Runtime Compilation). 如果包含同一库的不同版本,则会发出编译器错误。If different versions of the same libraries are included, a compile error is issued. 使用该新选项可以排除默认的 CLR 库,以便程序可以使用指定版本。The new option lets you exclude the default CLR libraries so that your program can use a specified version.

新的杂注指令 detect_mistmatch。New pragma directive detect_mistmatch. 杂注指令 detect_mismatch 能够在文件中放置一个要与其他具有相同名称的标记进行比较的标记。The pragma directive detect_mismatch lets you put a tag in your files that is compared to other tags that have the same name. 如果同一个名称存在多个值,则链接器将发出错误。If there are multiple values for the same name, the linker issues an error.

XOP 内部函数、FMA4 内部函数和 LWP 内部函数。XOP Intrinsics, FMA4 Intrinsics, and LWP Intrinsics. 添加了新的内部函数来支持针对 Visual Studio 2010 SP1 添加的 XOP 内部函数、针对 Visual Studio 2010 SP1 添加的 FMA4 内部函数和针对 Visual Studio 2010 SP1 处理器技术添加的 LWP 内部函数。New intrinsic functions have been added to support the XOP Intrinsics Added for Visual Studio 2010 SP1, FMA4 Intrinsics Added for Visual Studio 2010 SP1, and LWP Intrinsics Added for Visual Studio 2010 SP1 processor technologies. 使用 __cpuid、__cpuidex 可确定特定计算机上支持的处理器技术。Use __cpuid, __cpuidex to determine which processor technologies are supported on a particular computer.

Visual C++ 项目和生成系统Visual C++ Projects and the Build System

MSBuild. Visual C++ 解决方案和项目现在使用 MSBuild.exe(取代了 VCBuild.exe)生成。Visual C++ solutions and projects are now built by using MSBuild.exe, which replaces VCBuild.exe. MSBuild 同样是基于 XML 的、灵活的、可扩展的生成工具,可由其他 Visual Studio 语言和项目类型使用。MSBuild is the same flexible, extensible, XML-based build tool that is used by the other Visual Studio languages and project types. 由于此更改,Visual C++ 项目文件现在使用 XML 文件格式并具有文件扩展名 .vcxproj。Because of this change, Visual C++ project files now use an XML file format and have the .vcxproj file name extension. Visual Studio 早期版本的 Visual C++ 项目文件会自动转换为新文件格式。Visual C++ project files from earlier versions of Visual Studio are automatically converted to the new file format.

VC++ 目录。VC++ Directories. VC++ 目录设置现在位于两个位置。The VC++ directories setting is now located in two places. 使用项目属性页可为 VC++ 目录设置每个项目的值。Use project property pages to set per-project values for VC++ directories. 使用“属性管理器”和属性表可为 VC++ 目录设置每个配置的全局值。Use the Property Manager and a property sheet to set global, per-configuration values for VC++ directories.

项目到项目依赖项。Project-to-Project Dependencies. 在早期版本中,项目之间的定义依赖项存储在解决方案文件中。In earlier releases, defined dependencies between projects were stored in the solution file. 在这些解决方案转换为新项目文件格式时,依赖项会转换为项目到项目引用。When these solutions are converted to the new project file format, dependencies are converted to project-to-project references. 因为解决方案依赖项的概念与项目到项目引用的概念不同,所以此更改会影响应用程序。This change can affect applications because the concepts of solution dependencies and project-to-project references are different.

宏和环境变量。Macros and Environment Variables. 新的 _ITERATOR_DEBUG_LEVEL 宏将调用对迭代器的调试支持。The new _ITERATOR_DEBUG_LEVEL macro invokes debugging support for iterators. 使用此新宏取代旧的 _SECURE_SCL 和 _HAS_ITERATOR_DEBUGGING 宏。Use this macro instead of the older _SECURE_SCL and _HAS_ITERATOR_DEBUGGING macros.

Visual C++ 库Visual C++ Libraries

并发运行库。Concurrency Runtime Libraries. 并发运行时框架支持同时运行的应用程序和组件,并且它是在 Visual C++ 中进行并发应用程序编程的框架。The Concurrency Runtime framework supports applications and components that run simultaneously, and is the framework for programming concurrent applications in Visual C++. 为了支持并发应用程序编程,并行模式库 (PPL) 提供了用于执行细粒度并行操作的通用容器和算法。To support concurrent-application programming, the Parallel Patterns Library (PPL) provides general-purpose containers and algorithms for performing fine-grained parallelism. 异步代理库提供了用于粗粒度数据流和管道任务的基于角色的编程模型和消息传递接口。The Asynchronous Agents Library provides an actor-based programming model and message passing interfaces for coarse-grained dataflow and pipelining tasks.

标准 C++ 库。Standard C++ Library. 下表描述了对标准 C++ 库进行的很多更改。The following list describes many of the changes that have been made to the Standard C++ Library.

  • 使用了新的 rvalue 引用 C++ 语言功能来为标准模板库中的很多函数实现移动语义和完美转移。The new rvalue reference C++ language feature has been used to implement move semantics and perfect forwarding for many functions in the Standard Template Library. 移动语义和完美转移极大地提高了分配或指派变量或参数操作的性能。Move semantics and perfect forwarding greatly improve the performance of operations that allocate or assign variables or parameters.
  • 还使用了 rvalue 引用来实现新的 unique_ptr 类,这个新类是一个比 auto_ptr 类更安全的智能指针类型。Rvalue references are also used to implement the new unique_ptr class, which is a safer smart pointer type than the auto_ptr class. unique_ptr 类可移动但不可复制,在不影响安全的情况下实现严格的所有权语义,并且可以很好地与可识别 rvalue 引用的容器结合使用。The unique_ptr class is movable but not copyable, implements strict ownership semantics without affecting safety, and works well with containers that are aware of rvalue references. auto_ptr 类已被弃用。The auto_ptr class is deprecated.
  • 新增了 15 个函数,例如在 <algorithm> 标头中添加了 find_if_not、copy_if 和 is_sorted。Fifteen new functions, for example, find_if_not, copy_if, and is_sorted, have been added to the <algorithm> header.
  • 在 <memory> 标头中,利用新的 make_shared 函数可以在构造某个对象的同时轻松、可靠、高效地创建指向该对象的共享指针。In the <memory> header, the new make_shared function is a convenient, robust, and efficient way to make a shared pointer to an object at the same time the object is constructed.
  • <forward_list> 标头支持单独链接的列表。Singly linked lists are supported by the <forward_list> header.
  • 新的 cbegin、cend、crbegin 和 crend 成员函数提供可在整个容器中向前或向后移动的 const_iterator。The new cbegin, cend, crbegin, and crend member functions provide a const_iterator that moves forward or backward through a container.
  • <system_error> 标头和相关模板支持处理低级别系统错误。The <system_error> header and related templates support the processing of low-level system errors. exception_ptr 类的成员可用于在线程之间传输异常。Members of the exception_ptr class can be used to transport exceptions between threads.
  • <codecvt> 标头支持将 Unicode 字符的各种编码转换为其他编码。The <codecvt> header supports converting various encodings of Unicode characters to other encodings.
  • <allocators> 标头定义了可帮助基于节点的容器分配和释放内存块的多种模板。The <allocators> header defines several templates that help allocate and free memory blocks for node-based containers.
  • 对 <random> 标头进行了大量更新。There are numerous updates to the <random> header.

Microsoft 基础类 (MFC) 库Microsoft Foundation Class (MFC) Library

Windows 7 功能。Windows 7 Features. MFC 支持 Windows 7 的很多功能,例如,功能区用户界面 (UI)、任务栏、跳转列表、标签式缩略图、缩略图预览、进度栏、图标覆盖和搜索索引。MFC supports many Windows 7 features, for example, the Ribbon user interface (UI), the Taskbar, jump lists, tabbed thumbnails, thumbnail previews, the progress bar, icon overlay, and search indexing. 由于 MFC 自动支持 Windows 7 的很多功能,因此可能不必修改现有应用程序。Because MFC automatically supports many Windows 7 features, you may not have to modify your existing application. 若要支持新应用程序中的其他功能,可使用“MFC 应用程序向导”指定要使用的功能。To support other features in new applications, use the MFC Application Wizard to specify the functionality you want to use.

多点触控感知。Multi-touch Awareness. MFC 支持具有多点触控用户界面的应用程序,例如,针对 Microsoft Surface 操作系统编写的应用程序。MFC supports applications that have a multi-touch user interface, for example, applications that are written for the Microsoft Surface operating system. 多点触控应用程序可处理 Windows 触控消息和手势消息,也就是触控消息的组合。A multi-touch application can handle Windows touch messages and gesture messages, which are combinations of touch messages. 为应用程序注册触控事件和手势事件之后,操作系统就会将多点触控事件路由至事件处理程序。Just register your application for touch and gesture events and the operating system will route multi-touch events to your event handlers.

高 DPI 识别。High-DPI Awareness. 默认情况下,MFC 应用程序现在可以识别高 DPI。By default, MFC applications are now High-DPI-aware. 如果应用程序可以识别高 DPI(每英寸像素数),则操作系统可将窗口、文本和其他 UI 元素缩放至当前屏幕分辨率。If an application is High-DPI (high dots per inch) aware, the operating system can scale windows, text, and other UI elements to the current screen resolution. 这意味着,缩放的图像更可能是经过正确布局的,而不是经过剪切或像素化的。This means that a scaled image is more likely to be correctly laid out, and not clipped or pixelated.

重启管理器。Restart Manager. 重新启动管理器会在应用程序意外关闭或重新启动时,自动保存文档并重新启动该应用程序。The restart manager automatically saves documents and restarts your application if it unexpectedly closes or restarts. 例如,在自动更新关闭了某个应用程序后,可以使用重新启动管理器来启动该应用程序。For example, you can use the restart manager to start your application after it is closed by an automatic update. 有关如何将应用程序配置为使用重启管理器的更多信息,请参阅“如何:添加重启管理器支持”。For more information about how to configure your application to use the restart manager, see How to: Add Restart Manager Support.

CTaskDialog。CTaskDialog. 可以使用 CTaskDialog 类来代替标准 AfxMessageBox 消息框。The CTaskDialog class can be used instead of the standard AfxMessageBox message box. CTaskDialog 类能够显示和收集比标准消息框更多的信息。The CTaskDialog class displays and gathers more information than the standard message box does.

SafeInt 库SafeInt Library

新的 SafeInt 库执行安全的算数运算,可防止整数溢出。The new SafeInt Library performs safe arithmetic operations that account for integer overflow. 该库还会比较不同类型的整数。This library also compares different kinds of integers.

新的活动模板库 (ATL) 宏New Active Template Library (ATL) macros

向 ATL 中添加了新的宏来扩展 PROP_ENTRY_TYPE 和 PROP_ENTRY_TYPE_EX 的功能。New macros have been added to ATL to expand the functionality of PROP_ENTRY_TYPE and PROP_ENTRY_TYPE_EX. PROP_ENTRY_INTERFACE 和 PROP_ENTRY_INTERFACE_EX 可用于添加有效的 CLSID 列表。PROP_ENTRY_INTERFACE and PROP_ENTRY_INTERFACE_EX let you add a list of valid CLSIDs. PROP_ENTRY_INTERFACE_CALLBACK 和 PROP_ENTRY_INTERFACE_CALLBACK_EX 可用于指定一个回调函数来确定 CLSID 是否有效。PROP_ENTRY_INTERFACE_CALLBACK and PROP_ENTRY_INTERFACE_CALLBACK_EX let you specify a callback function to determine whether a CLSID is valid.

/analyze 警告/analyze Warnings

已从 C 运行时 (CRT)、MFC 和 ATL 库中删除了大多数 /analyze(企业代码分析)警告。Most /analyze (Enterprise Code Analysis) warnings have been removed from the C Run-Time (CRT), MFC, and ATL libraries.

动画和 D2D 支持Animation and D2D support

MFC 现在支持动画和 Direct2D 图形。MFC now supports animation and Direct2D graphics. MFC 库中新增了一些 MFC 类和函数来支持此功能。The MFC library has several new MFC classes and functions to support this functionality. 此外还新增了两个演练来分别演示如何将 D2D 对象和动画对象添加到项目中。There are also two new walkthroughs to show how to add a D2D object and an animation object to a project. 这两个演练分别为“演练:向 MFC 项目添加 D2D 对象”和“演练:向 MFC 项目添加动画”。These walkthroughs are Walkthrough: Adding a D2D Object to an MFC Project and Walkthrough: Adding Animation to an MFC Project.

IDEIDE

改进的 IntelliSense。Improved IntelliSense. 对用于 Visual C++ 的 IntelliSense 进行了完全重新设计,以便能够更快、更准确并且有能力处理更大的项目。IntelliSense for Visual C++ has been completely redesigned to be faster, more accurate, and able to handle larger projects. 为了完成此次改进,IDE 对开发人员查看和修改源代码的方式与 IDE 使用源代码和项目设置生成解决方案的方式进行了区分。To achieve this improvement, the IDE makes a distinction between how a developer views and modifies source code, and how the IDE uses source code and project settings to build a solution. 由于这种责任分离,“类视图”和新的“导航到”对话框这样的浏览功能将由一个基于新的 SQL Server 桌面数据库 (.sdf) 文件(取代了旧版的无编译浏览 (.ncb) 文件)的系统进行处理。Because of this separation of duties, browsing features such as Class View and the new Navigate To dialog box are handled by a system that is based on a new SQL Server desktop database (.sdf) file that replaces the old no compile browse (.ncb) file. IntelliSense 功能(例如,快速信息、自动完成和参数帮助)仅在需要时才会分析转换单元。IntelliSense features such as Quick Information, Auto Completion, and Parameter Help parse translation units only when required. 混合功能(例如,新的调用层次结构窗口)结合了浏览和 IntelliSense 功能。Hybrid features such as the new Call Hierarchy window use a combination of the browse and IntelliSense features. 由于 IntelliSense 仅处理你目前需要的信息,因此 IDE 的响应速度更快。Because IntelliSense processes only the information that you require at the moment, the IDE is more responsive. 另外,由于信息更新,IDE 视图和窗口更准确了。Also, because information is more up to date, IDE views and windows are more accurate. 最后,由于 IDE 基础结构的组织更合理、处理能力更强并且可伸缩性更大,因此可以处理更大的项目。Finally, because the IDE infrastructure is better organized, more capable, and more scalable, it can handle larger projects.

改进的 IntelliSense 错误。Improved IntelliSense Errors. IDE 可更好地检测可能会损失 IntelliSense 的错误,并在错误下显示红色波浪下划线。The IDE better detects errors that could cause a loss of IntelliSense and displays red wavy underlines under them. 此外,IDE 还会在“错误列表窗口”中报告 IntelliSense 错误。In addition, the IDE reports IntelliSense errors to the Error List Window. 若要显示导致问题的代码,请在“错误列表窗口”中双击错误。To display the code that is causing the problem, double-click the error in the Error List Window.

#include 自动完成功能。#include Auto-Complete Feature. IDE 支持 #include 关键字自动完成。The IDE supports auto-completion for the #include keyword. 在键入 #include 时,IDE 会创建一个包含有效头文件的下拉列表框。When you type #include, the IDE creates a drop-down list box of valid header files. 如果继续键入文件名,则 IDE 会基于输入内容筛选该列表。If you continue by typing a file name, the IDE filters the list based on your entry. 可以随时从该列表中选择要包含的文件。At any point, you can select from the list the file you want to include. 这样可快速地包含文件,而无需知道确切的文件名。This lets you quickly include files without knowing the exact file name.

定位到。Navigate To. 可以利用“导航到”对话框搜索项目中与指定字符串匹配的所有符号和文件。The Navigate To dialog box lets you search for all symbols and files in your project that match a specified string. 随着你在搜索字符串中键入其他字符,搜索结果会即时进行修改。Search results are immediately revised as you type additional characters in your search string. “结果”反馈字段会告知已找到的项数,并帮助决定是否要限制搜索。The Results feedback field tells you the number of items found and helps you decide whether to constrain your search. “种类/范围”、“位置”和“预览”反馈字段可帮助排除名称类似的项。The Kind/Scope, Location, and Preview feedback fields help you disambiguate items that have similar names. 此外,你可以扩展此功能以支持其他编程语言。In addition, you can extend this feature to support other programming languages.

并行调试和分析。Parallel Debugging and Profiling. Visual Studio 调试器可识别并发运行时,帮助排除并行处理应用程序故障。The Visual Studio debugger is aware of the Concurrency Runtime and helps you troubleshoot parallel processing applications. 可使用新的并发探查器工具直观地显示应用程序的总体行为。You can use the new concurrency profiler tool to visualize the overall behavior of your application. 此外,可使用新的工具窗口直观地显示任务及其调用堆栈的状态。Also, you can use new tool windows to visualize the state of tasks and their call stacks.

功能区设计器。Ribbon Designer. 功能区设计器是一个图形编辑器,可以帮助你创建和修改 MFC 功能区 UI。The Ribbon Designer is a graphical editor that lets you create and modify an MFC ribbon UI. 最终的功能区 UI 由基于 XML 的资源文件 (.mfcribbon-ms) 表示。The final ribbon UI is represented by an XML-based resource file (.mfcribbon-ms). 对于现有应用程序,可以通过临时添加一些代码行,然后调用功能区设计器来捕获当前功能区 UI。For existing applications, you can capture your current ribbon UI by temporarily adding a few lines of code and then invoking the Ribbon Designer. 创建功能区资源文件之后,可以使用一些用于加载功能区资源的语句来替换手写的功能区 UI 代码。After the ribbon resource file is created, you can replace your handwritten ribbon UI code with a few statements that load the ribbon resource.

调用层次结构。Call Hierarchy. 利用“调用层次结构”窗口可以导航到由特定函数调用的所有函数,也可导航到调用特定函数的所有函数。The Call Hierarchy window lets you navigate to all functions that are called by a particular function, or to all functions that call a particular function.

工具Tools

MFC 类向导。MFC Class Wizard. Visual C++ 2010 恢复了备受好评的 MFC 类向导工具。Visual C++ 2010 brings back the well-regarded MFC Class Wizard tool. 通过使用 MFC 类向导,可以很方便地向项目中添加类、消息和变量,而不必手动修改源文件集。The MFC Class Wizard is a convenient way to add classes, messages, and variables to a project without having to manually modify sets of source files.

ATL 控件向导。ATL Control Wizard. ATL 控件向导不再自动填充 ProgID 字段。The ATL Control Wizard no longer automatically populates the ProgID field. 如果某个 ATL 控件没有 ProgID,则其他工具可能无法使用该控件。If an ATL control does not have a ProgID, other tools may not work with it. 例如,“插入活动控件”对话框就是一种需要控件具有 ProgID 的工具。One example of a tool that requires controls to have a ProgID is the Insert Active Control dialog box. 有关此对话框的更多信息,请参阅“插入 ActiveX 控件对话框”。For more information about the dialog box, see Insert ActiveX Control Dialog Box.

Microsoft 宏汇编程序参考Microsoft Macro Assembler Reference

新增的 YMMWORD 数据类型支持 Intel 高级矢量扩展 (AVX) 指令中包含的 256 位多媒体操作数。The addition of the YMMWORD data type supports the 256-bit multimedia operands that are included in the Intel Advanced Vector Extensions (AVX) instructions.

Visual Studio 2008 中 C++ 的新增功能What's New for C++ in Visual Studio 2008

Visual C++ 集成开发环境 (IDE)Visual C++ Integrated Development Environment (IDE)

  • 在 ATL、MFC 和 Win32 应用程序中创建的对话框现在符合 Windows Vista 样式指南。Dialog boxes that are created in ATL, MFC, and Win32 applications now comply with the Windows Vista style guidelines. 使用 Visual Studio 2008 创建新项目时,插入应用程序中的所有对话框将符合 Windows Vista 样式指南。When you create a new project by using Visual Studio 2008, all dialog boxes that you insert into your application will comply with the Windows Vista style guideline. 如果重新编译使用早期版本的 Visual Studio 创建的项目,所有现有对话框将保持以前的外观。If you recompile a project that you created with an earlier version of Visual Studio, any existing dialog boxes will maintain the same look that they previously had. 有关如何将对话框插入应用程序的更多信息,请参阅“对话框编辑器”。For more information about how to insert dialog boxes into your application, see Dialog Editor.

  • ATL 项目向导现在具有一个用于为所有用户注册组件的选项。The ATL Project wizard now has an option to register components for all users. 从 Visual Studio 2008 开始,ATL 项目向导创建的 COM 组件和类型库都在注册表的 HKEY_CURRENT_USER 节点中注册,除非选择的是为所有用户注册组件。Beginning with Visual Studio 2008, the COM components and type libraries that are created by the ATL Project wizard are registered in the HKEY_CURRENT_USER node of the registry unless you select Register component for all users.

  • ATL 项目向导不再提供用于创建属性化 ATL 项目的选项。The ATL Project wizard no longer provides an option to create attributed ATL projects. 从 Visual Studio 2008 开始,ATL 项目向导不再具有用于更改新项目属性化状态的选项。Beginning with Visual Studio 2008, the ATL Project wizard does not have an option to change the attributed status of a new project. 该向导创建的所有新 ATL 项目现在都未经属性化。All new ATL projects that the wizard creates are now unattributed.
  • 写入注册表时可以进行重定向。Writing to the registry can be redirected. 随着 Windows Vista 的引入,写入注册表的特定区域需要在提升模式下运行程序。With the introduction of Windows Vista, writing to certain areas of the registry requires a program to run in elevated mode. 但不需要始终在提升模式下运行 Visual Studio。It is not desirable to always run Visual Studio in elevated mode. 无需任何编程更改,按用户重定向可以自动将注册表写入操作从 HKEY_CLASSES_ROOT 重定向到 HKEY_CURRENT_USER。Per-user redirection automatically redirects registry writes from HKEY_CLASSES_ROOT to HKEY_CURRENT_USER without any programming changes.
  • 类设计器现在为本机 C++ 代码提供有限支持。The Class Designer now has limited support for native C++ code. 在早期版本的 Visual Studio 中,类设计器仅适用于 Visual C# 和 Visual Basic。In earlier versions of Visual Studio, the Class Designer worked only with Visual C# and Visual Basic. C++ 用户现在可以使用类设计器,但只能在只读模式下使用。C++ users can now use the Class Designer, but only in read-only mode. 有关如何在 C++ 中使用类设计器的更多信息,请参阅“在类设计器中使用 Visual C++ 代码”。For more information about how to use the Class Designer with C++, see Working with Visual C++ Code in Class Designer.
  • 项目向导不再提供用于创建 C++ SQL Server 项目的选项。The project wizard no longer has an option to create a C++ SQL Server project. 从 Visual Studio 2008 开始,新建项目向导没有创建 C++ SQL Server 项目的选项。Beginning with Visual Studio 2008, the new project wizard does not have an option to create a C++ SQL Server project. 使用 Visual Studio 早期版本创建的 SQL Server 项目仍将编译并正常运行。SQL Server projects created by using an earlier version of Visual Studio will still compile and work correctly.

Visual C++ 库Visual C++ Libraries

常规General

  • 可将应用程序绑定到特定版本的 Visual C++ 库。Applications can be bound to specific versions of the Visual C++ libraries. 有时应用程序依赖于版本发布后对 Visual C++ 库所做的更新。Sometimes an application depends on updates that were made to the Visual C++ libraries after a release. 在这种情况下,在具有早期版本库的计算机上运行应用程序可能会导致意外行为。In this case, running the application on a computer that has earlier versions of the libraries can cause unexpected behavior. 现在可以将应用程序绑定到特定版本的库,使应用程序不会在具有早期版本库的计算机上运行。You can now bind an application to a specific version of the libraries so that it will not run on a computer that has an earlier version of the libraries.

STL/CLR 库STL/CLR Library

  • Visual C++ 现在包括了 STL/CLR 库。Visual C++ now includes the STL/CLR Library. STL/CLR 库由标准模板库 (STL)(标准 C++ 库的一个子集)打包而成,与 C++ 和 .NET Framework 公共语言运行时 (CLR) 一起使用。The STL/CLR Library is a packaging of the Standard Template Library (STL), a subset of the Standard C++ Library, for use with C++ and the .NET Framework common language runtime (CLR). 通过 STL/CLR,现在可以在托管环境中使用 STL 的所有容器、迭代器和算法。With STL/CLR, you can now use all the containers, iterators, and algorithms of STL in a managed environment.

MFC 库MFC Library

  • Windows Vista 支持公共控件。Windows Vista supports Common Controls. 已经添加了 18 个新类或现有类中的 150 多个方法,用于支持 Windows Vista 中的功能,或改进当前 MFC 类中的功能。Over 150 methods in 18 new or existing classes have been added to support features in Windows Vista, or to improve functionality in current MFC classes.
  • 使用新的 CNetAddressCtrl 类可以输入和验证 IPv4 和 IPv6 地址或 DNS 名称。The new CNetAddressCtrl class enables you to input and validate IPv4 and IPv6 addresses or DNS names.
  • 新的 CPagerCtrl 类简化了 Windows 页导航控件的使用。The new CPagerCtrl class simplifies use of the Windows pager control.
  • 新的 CSplitButton 类简化了 Windows 拆分按钮控件的使用以选择默认或可选操作。The new CSplitButton class simplifies the use of the Windows splitbutton control to select a default or optional action.

C++ 支持库C++ Support Library

  • C++ 引入了封送处理库。C++ introduces the marshaling library. 封送处理库为在本机和托管环境之间封送数据提供了一个易于使用的优化方法。The marshaling library provides an easy and optimized way to marshal data between native and managed environments. 封送处理库可以替代其他更复杂、效率更低的方法(例如使用 PInvoke)。The library is an alternative to more complex and less efficient approaches such as Using PInvoke. 有关详细信息,请参阅“C++ 中的封送处理概述”。See Overview of Marshaling in C++ for more information.

ATL 服务器ATL Server

  • ATL 服务器作为共享源项目发布。ATL Server is released as a shared source project.
  • 大多数 ATL 服务器基本代码已作为共享源项目发布在 CodePlex 上,而不是作为 Visual Studio 2008 的一部分进行安装。Most of the ATL Server code base has been released as a shared source project on CodePlex and is not installed as part of Visual Studio 2008. 与 ATL 服务器相关联的多个文件不再属于 Visual Studio。Several files associated with ATL Server are no longer part of Visual Studio. 有关已删除文件的列表,请参阅“已删除的 ATL 服务器文件”。For the list of removed files, see Removed ATL Server Files.
  • 来自 atlenc.h 的数据编码和解码类以及来自 atlutil.h 和 atlpath.h 的实用工具函数和类现在都属于 ATL 库。Data encoding and decoding classes from atlenc.h and utility functions and classes from atlutil.h and atlpath.h are now part of the ATL library.
  • Microsoft 将继续支持早期版本的 Visual Studio 中包含的 ATL 服务器版本,只要这些版本的 Visual Studio 受到支持。Microsoft will continue to support versions of ATL Server that are included in earlier releases of Visual Studio as long as those versions of Visual Studio are supported. CodePlex 将继续以社区项目的形式开发 ATL 服务器代码。CodePlex will continue development of the ATL Server code as a community project. Microsoft 不支持 CodePlex 版本的 ATL 服务器。Microsoft does not support a CodePlex version of ATL Server.

Visual C++ 编译器和链接器Visual C++ Compiler and Linker

编译器的更改Compiler Changes

  • 编译器支持托管增量生成。The compiler supports managed incremental builds. 如果指定此选项,则编译器在引用程序集更改时不会重新编译代码。When you specify this option, the compiler will not recompile code when a referenced assembly changes. 它将执行增量生成。Instead it will perform an incremental build. 仅当更改影响依赖代码时才会重新编译文件。Files are recompiled only if the changes affect the dependent code.
  • 不再支持与 ATL 服务器相关的属性。Attributes related to ATL Server are no longer supported. 编译器不再支持曾与 ATL 服务器直接相关的一些属性。The compiler no longer supports several attributes that were directly related to ATL Server. 有关已删除属性的完整列表,请参阅“重大更改”。For a complete list of the removed attributes, see Breaking Changes.
  • 编译器支持 Intel 内核微架构。The compiler supports Intel Core microarchitecture. 编译器包含在代码生成过程中对 Intel 内核微架构进行的优化。The compiler contains tuning for the Intel Core microarchitecture during code generation. 该优化默认启用,并且不能禁用,因为它也用于 Pentium 4 和其他处理器。By default, this tuning is on and cannot be disabled as it also helps Pentium 4 and other processors.
  • 内部函数支持更新的 AMD 和 Intel 处理器。Intrinsics support newer AMD and Intel processors. 多条新的内部函数指令在新型 AMD 和 Intel 处理器中提供更强大的功能。Several new intrinsic instructions support the greater functionality in more recent AMD and Intel processors. 有关新增内部函数的更多信息,请参阅“流式处理 SIMD 扩展 3 的补充指令”、“流式处理 SIMD 扩展 4 的指令”、“SSE4A 和高级位操作内部函数”、“AES 内部函数”、“_mm_clmulepi64_si128”和“__rdtscp”。For more information about the new intrinsics, see Supplemental Streaming SIMD Extensions 3 Instructions, Streaming SIMD Extensions 4 Instructions, SSE4A and Advanced Bit Manipulation Intrinsics, AES Intrinsics, _mm_clmulepi64_si128, and __rdtscp.
  • __cpuid 函数已更新。The __cpuid function is updated. __cpuid、__cpuidex 函数现在支持最新修订版的 AMD 和 Intel 处理器的多项新功能。The __cpuid, __cpuidex functions now support several new features from the latest revisions of AMD and Intel processors. __cpuidex 内部函数是新增的,并且能从最新处理器收集更多信息。The __cpuidex intrinsic is new and gathers more information from recent processors.
  • /MP 编译器选项缩短了总生成时间。The /MP compiler option reduces total build time. /MP 选项通过创建多个同时编译文件的进程,显著减少了编译多个源文件需要的总时间。The /MP option can significantly reduce the total time to compile several source files by creating several processes that compile the files simultaneously. 此选项在支持超线程、多处理器或多内核的计算机上尤其有用。This option is especially useful on computers that support hyperthreading, multiple processors, or multiple cores.
  • /Wp64 编译器选项和 __w64 关键字已弃用。The /Wp64 compiler option and __w64 keyword are deprecated. /Wp64 编译器选项和 __w64 关键字(用于检测 64 位可移植性问题)已弃用,并将从未来版本的编译器中删除。The /Wp64 compiler option and __w64 keyword, which detect 64-bit portability issues, are deprecated and will be removed in a future version of the compiler. 请改用面向 64 位平台的 Visual C++ 编译器来代替此编译器选项和关键字。Instead of this compiler option and keyword, use a Visual C++ compiler that targets a 64-bit platform.
  • /Qfast_transcendentals 生成先验函数的内联代码。/Qfast_transcendentals generates inline code for transcendental functions.
  • /Qimprecise_fwaits 在使用 /fp:except 编译器选项时删除 try 块内部的 fwait 命令。/Qimprecise_fwaits removes the fwait commands internal to try blocks when you use the /fp:except compiler option.

链接器的更改Linker Changes

  • 用户帐户控制信息现在由 Visual C++ 链接器 (link.exe) 嵌入到可执行文件的清单文件中。User Account Control information is now embedded into manifest files for executables by the Visual C++ linker (link.exe). 默认情况下启用此功能。This feature is enabled by default. 有关如何禁用此功能或如何修改默认行为的更多信息,请参阅“/MANIFESTUAC(将 UAC 信息嵌入到清单中)”。For more information about how to disable this feature, or how to modify the default behavior, see /MANIFESTUAC (Embeds UAC information in manifest).
  • 链接器现在具有 /DYNAMICBASE 选项,用于启用 Windows Vista 的地址空间布局随机化功能。The linker now has the /DYNAMICBASE option to enable the Address Space Layout Randomization feature of Windows Vista. 此选项修改可执行文件标头,以指示是否应在加载时对应用程序进行随机变基。This option modifies the header of an executable to indicate whether the application should be randomly rebased at load time.

Visual Studio 2005 中 C++ 的新增功能What's New for C++ in Visual Studio 2005

Visual C++ 2005 Service Pack 1 中新增了以下功能:The following features were new in Visual C++ 2005 Service Pack 1:

面向 x86 和 x64 的内部函数Intrinsics for x86 and x64

  • __halt__halt
  • __lidt__lidt
  • __nop__nop
  • __readcr8__readcr8
  • __sidt__sidt
  • __svm_clgi__svm_clgi
  • __svm_invlpga__svm_invlpga
  • __svm_skinit__svm_skinit
  • __svm_stgi__svm_stgi
  • __svm_vmload__svm_vmload
  • __svm_vmrun__svm_vmrun
  • __svm_vmsave__svm_vmsave
  • __ud2__ud2
  • __vmx_off__vmx_off
  • __vmx_vmptrst__vmx_vmptrst
  • __writecr8__writecr8

仅限 x64 的内部函数Intrinsics for x64 Only

  • __vmx_on__vmx_on
  • __vmx_vmclear__vmx_vmclear
  • __vmx_vmlaunch__vmx_vmlaunch
  • __vmx_vmptrld__vmx_vmptrld
  • __vmx_vmread__vmx_vmread
  • __vmx_vmresume__vmx_vmresume
  • __vmx_vmwrite__vmx_vmwrite

新语言关键字New Language Keywords

__sptr、__uptr__sptr, __uptr

编译器的新增功能New Compiler Features

此版本对编译器进行了重大更改。The compiler has breaking changes in this release.

  • 64 位本机和跨平台编译器。`64-bit native and cross-compilers.
  • 添加了 /analyze(企业代码分析)编译器选项。/analyze (Enterprise Code Analysis) compiler option has been added.
  • 添加了 /bigobj 编译器选项。/bigobj compiler option has been added.
  • 添加了 /clr:pure、/clr:safe 和 /clr:oldSyntax。/clr:pure, /clr:safe, and /clr:oldSyntax have been added. (后来已在 Visual Studio 2015 中弃用,并已从 Visual Studio 2017 中删除。)(Later deprecated in Visual Studio 2015 and removed in Visual Studio 2017.)
  • 已弃用的编译器选项:此版本中很多编译器选项已弃用,请参阅“已弃用的编译器选项”以获取详细信息。Deprecated compiler options: many compiler options have been deprecated in this release; see Deprecated Compiler Options for more information.
  • 减少了 /clr 代码中的双重形式转换;请参阅“双重形式转换 (C++)”以获取详细信息。Double thunking in /clr code is reduced; see Double Thunking (C++) for more information.
  • /EH(异常处理模型)或 /EHs 将不能再用于捕捉非引发性异常;请使用 /EHa。/EH (Exception Handling Model) or /EHs can no longer be used to catch an exception that is raised with something other than a throw; use /EHa.
  • 添加了 /errorReport(报告内部编译器错误)编译器选项。/errorReport (Report Internal Compiler Errors) compiler option has been added.
  • 添加了 /favor(64 位优化)编译器选项。/favor (Optimize for 64) compiler option has been added.
  • 添加了 /FA、/Fa(列表文件)编译器选项。/FA, /Fa (Listing File) compiler option has been added.
  • 添加了 /FC(所诊断源代码文件的完整路径)编译器选项。/FC (Full Path of Source Code File in Diagnostics) compiler option has been added.
  • 添加了 /fp(指定浮点行为)编译器选项。/fp (Specify Floating-Point Behavior) compiler option has been added.
  • 添加了 /G(处理器优化)选项编译器选项。/G (Optimize for Processor) Options compiler option has been added.
  • 添加了 /G(处理器优化)选项编译器选项。/G (Optimize for Processor) Options compiler option has been added.
  • 删除了 /G3、/G4、/G5、/G6、/G7 和 /GB 编译器选项。/G3, /G4, /G5, /G6, /G7, and /GB compiler options have been removed. 该编译器现在使用“混合模式”,会尝试为所有体系结构创建最佳输出文件。The compiler now uses a "blended model" that attempts to create the best output file for all architectures.
  • /Gf 已被移除。/Gf has been removed. 请改用 /GF(消除重复的字符串)。Use /GF (Eliminate Duplicate Strings) instead.
  • /GL(全程序优化)现与 /CLRHEADER 兼容。/GL (Whole Program Optimization) is now compatible with /CLRHEADER.
  • 现在 /GR 默认为打开状态。/GR is now on by default.
  • /GS(缓冲区安全检查)现在可对容易受到攻击的指针参数提供安全保护。/GS (Buffer Security Check) now provides security protection for vulnerable pointer parameters. 现在 /GS 默认为打开状态。/GS is now on by default. /GS 现在也可用于通过 /clr(公共语言运行时编译)编译为 MSIL 的函数。/GS now also works on functions compiled to MSIL with /clr (Common Language Runtime Compilation).
  • 添加了 /homeparams(将寄存器参数复制到堆栈)编译器选项。/homeparams (Copy Register Parameters to Stack) compiler option has been added.
  • 添加了 /hotpatch(创建可热修补的映像)编译器选项。/hotpatch (Create Hotpatchable Image) compiler option has been added.
  • 更新了内联函数试探法;请参阅 inline、__inline、__forceinline 和 inline_depth 以获取详细信息Inline function heuristics have been updated; see inline, __inline, __forceinline and inline_depth for more information
  • 添加了很多内部函数,而且很多以前未记录的内部函数现在都已记录。Many new intrinsic functions have been added, and many previously undocumented intrinsics are now documented.
  • 默认情况下,任何对 new 的调用失败都将引发异常。By default, any call to new that fails will throw an exception.
  • 删除了 /ML 和 /MLd 编译器选项。/ML and /MLd compiler options have been removed. Visual C++ 不再支持单线程静态链接的 CRT 库支持。Visual C++ no longer supports single-threaded, statically linked CRT library support.
  • 编译器已实现命名返回值优化,当你用 /O1、/O2(最小化大小、最大化速度)、/Og(全局优化)和 /Ox(完全优化)进行编译时会启用此优化。The compiler implemented the Named Return Value Optimization, which is enabled when you compile with /O1, /O2 (Minimize Size, Maximize Speed), /Og (Global Optimizations), and /Ox (Full Optimization).
  • 删除了 /Oa 编译器选项,它将被忽略且没有提示;请使用 noalias 或 restrict__declspec 修饰符来指定编译器命名别名的方式。/Oa compiler option has been removed but will be silently ignored; use the noalias or restrict__declspec modifiers to specify how the compiler does aliasing.
  • 删除了 /Op 编译器选项。/Op compiler option had been removed. 请改用 /fp(指定浮点行为)。Use /fp (Specify Floating-Point Behavior) instead.
  • Visual C++ 现在支持 OpenMP。OpenMP is now supported by Visual C++.
  • 添加了 /openmp(启用 OpenMP 2.0 支持)编译器选项。/openmp (Enable OpenMP 2.0 Support) compiler option has been added.
  • 删除了 /Ow 编译器选项,它将被忽略且没有提示。/Ow compiler option has been removed but will be silently ignored. 请使用 noalias 或 restrict__declspec 修饰符来指定编译器命名别名的方式。Use the noalias or restrict__declspec modifiers to specify how the compiler does aliasing.

按配置文件优化Profile-Guided Optimizations

  • /QI0f 已被移除。/QI0f has been removed.
  • /QIfdiv 已被移除。/QIfdiv has been removed.
  • 添加了 /QIPF_B(B CPU 单步执行的勘误表)编译器选项。/QIPF_B (Errata for B CPU Stepping) compiler option has been added.
  • 添加了 /QIPF_C(C CPU 单步执行的勘误表)编译器选项。/QIPF_C (Errata for C CPU Stepping) compiler option has been added.
  • 添加了 /QIPF_fr32(不使用高 96 浮点寄存器)编译器选项。/QIPF_fr32 (Do Not Use Upper 96 Floating Point Registers) compiler option has been added.
  • 添加了 /QIPF_noPIC(生成依赖于位置的代码)编译器选项。/QIPF_noPIC (Generate Position Dependent Code) compiler option has been added.
  • 添加了 /QIPF_restrict_plabels(假定运行时不创建任何函数)编译器选项。/QIPF_restrict_plabels (Assume No Functions Created at Run Time) compiler option has been added.

编译器和链接器中的 Unicode 支持Unicode Support in the Compiler and Linker

  • /vd(禁用构造置换)现在允许你对正在构造(使用 /vd2)的对象使用 dynamic_cast 运算符/vd (Disable Construction Displacements) now allows you to use dynamic_cast Operator on an object being constructed (/vd2)
  • /YX 编译器选项已被移除。/YX compiler option has been removed. 请改用 /Yc(创建预编译头文件) 或 /Yu(使用预编译头文件)。Use /Yc (Create Precompiled Header File) or /Yu (Use Precompiled Header File) instead. 如果从生成配置中删除 /YX,且不提供替换项,则可能会加快生成速度。If you remove /YX from your build configurations and replace it with nothing, it can result in faster builds.
  • 现在 /Zc:forScope 默认为打开状态。/Zc:forScope is now on by default.
  • 现在 /Zc:wchar_t 默认为打开状态。/Zc:wchar_t is now on by default.
  • /Zd 编译器选项已被移除。/Zd compiler option has been removed. 不再支持仅限行号的调试信息。Line-number only debugging information is no longer supported. 请改用 /Zi(有关更多信息,请参见 /Z7、/Zi、/ZI(调试信息格式))。Use /Zi instead (see /Z7, /Zi, /ZI (Debug Information Format) for more information).
  • /Zg 现在仅对 C 源代码文件有效,对 C++ 源代码文件无效。/Zg is now only valid on C source code files, and not on C++ source code files.
  • 添加了 /Zx(调试经过优化的 Itanium 代码)编译器选项。/Zx (Debug Optimized Itanium Code) compiler option has been added.

新语言功能New Language Features

  • Attributeattribute 现已弃用。The attributeattribute is now deprecated.
  • 添加了 appdomain__declspec 修饰符。appdomain__declspec modifier has been added.
  • 添加了 __clrcall 调用约定。__clrcall calling convention has been added.
  • 借助于已弃用的 (C++)declspec 修饰符,用户可以在试图访问已弃用的类或函数时,指定将在编译时显示的字符串。deprecated (C++)declspec modifier now allows you to specify a string that will be displayed at compile time, when a user tries to access a deprecated class or function.
  • dynamic_cast 运算符有重大更改。dynamic_cast Operator has breaking changes.
  • 本机枚举现在允许指定基础类型。Native enums now allow you to specify the underlying type.
  • 添加了 jitintrinsicdeclspec 修饰符。jitintrinsicdeclspec modifier has been added.
  • 添加了 noaliasdeclspec 修饰符。noaliasdeclspec modifier has been added.
  • 添加了 process__declspec 修饰符。process__declspec modifier has been added.
  • abstract、override 和 sealed 对本机编译有效。abstract, override, and sealed are valid for native compilations.
  • 添加了 __restrict 关键字。__restrict keyword has been added.
  • 添加了 restrictdeclspec 修饰符。restrictdeclspec modifier has been added.
  • __thiscall 现在是关键字。__thiscall is now a keyword.
  • __unaligned 关键字现已记录。__unaligned keyword is now documented.
  • volatile (C++) 已更新与优化相关的行为。volatile (C++) has updated behavior with respect to optimizations.

预处理器的新增功能New Preprocessor Features

  • 添加了预定义宏 __CLR_VER。__CLR_VER predefined macro added.
  • 注释 (C/C++) 杂注现在接受 /MANIFESTDEPENDENCY 作为链接器注释。The comment (C/C++) pragma now accepts /MANIFESTDEPENDENCY as a linker comment. 注释的 exestr 选项现已弃用。The exestr option to comment is now deprecated.
  • embedded_idl 属性(#import 指令)现在具有可选参数。embedded_idl attribute (The #import Directive) now takes an optional parameter.
  • fenv_access 杂注fenv_access pragma
  • float_control 杂注float_control pragma
  • fp_contract 杂注fp_contract pragma
  • 如果杂注的托管和非托管部分中存在全局变量,则不会按照声明全局变量的顺序初始化全局变量。Global variables will not be initialized in the order they are declared if you have global variables in pragma managed, unmanaged and unmanaged sections. 这是一项潜在的重大更改,例如,如果使用托管的全局变量来初始化非托管全局变量,则需要一个构造完整的托管对象。This is a potential breaking change if, for example, an unmanaged global variable is initialized with a managed global variables, and a fully constructed managed object is required.
  • 用 init_seg 指定的部分现为只读状态,而不是早期版本中的读/写。Sections specified with init_seg are now read only, and not read/write as in previous versions.
  • inline_depth 默认值现为 16。inline_depth default is now 16. 在 Visual C++ .NET 2003 中,默认值 16 也有效。A default of 16 was also in effect in Visual C++ .NET 2003.
  • 添加了预定义宏 _INTEGRAL_MAX_BITS,请参阅“预定义宏”。_INTEGRAL_MAX_BITS predefined macro added, see Predefined Macros.
  • 添加了预定义宏 _M_CEE、_M_CEE_PURE 和 _M_CEE_SAFE,请参阅“预定义宏”。_M_CEE, _M_CEE_PURE, and _M_CEE_SAFE predefined macros added, see Predefined Macros.
  • 添加了预定义宏 _M_IX86_FP。_M_IX86_FP predefined macro added.
  • 添加了预定义宏 _M_X64。_M_X64 predefined macro added.
  • make_public 杂注make_public pragma
  • 更新了托管和非托管的杂注语法(现在有推送和弹出)managed, unmanaged pragma syntax updated (now has push and pop)
  • 现在 #using 指令在所有 /clr 编译中隐式引用 mscorlib.dll。mscorlib.dll is now implicitly referenced by The #using Directive in all /clr compilations.
  • 添加了预定义宏 _OPENMP。_OPENMP predefined macro added.
  • 更新了优化杂注,a 和 w 不再是有效参数。optimize pragma has been updated, a and w are no longer valid parameters.
  • 添加了 no_registry#import 属性。no_registry#import attribute has been added.
  • 添加了 region、endregion 杂注region, endregion pragmas added
  • 添加了预定义宏 _VC_NODEFAULTLIB。_VC_NODEFAULTLIB predefined macro added.
  • 现在实现了 Variadic 宏。Variadic Macros are now implemented.
  • vtordisp 已弃用,并将从 Visual C++ 的未来版本移除。vtordisp is deprecated and will be removed in a future release of Visual C++.
  • warning 杂注现在具有 suppress 说明符。The warning pragma now has the suppress specifier.

链接器的新增功能New Linker Features

  • 现在允许将模块(非程序集 MSIL 输出文件)作为链接器的输入内容。Modules (non-assembly MSIL output files) are now allowed as input to the linker.
  • 添加了 /ALLOWISOLATION(清单查找)链接器选项。/ALLOWISOLATION (Manifest Lookup) linker option has been added.
  • 更新了 /ASSEMBLYRESOURCE(嵌入托管资源),现在可以指定程序集中的资源名称,以及指定该资源在程序集中为私有。/ASSEMBLYRESOURCE (Embed a Managed Resource) has been updated to now allow you to specify the name of the resource in the assembly, and to specify that the resource is private in the assembly.
  • 添加了 /CLRIMAGETYPE(指定 CLR 映像的类型)链接器选项。/CLRIMAGETYPE (Specify Type of CLR Image) linker option has been added.
  • 添加了 /CLRSUPPORTLASTERROR(为 PInvoke 调用保留上次的错误代码)链接器选项。/CLRSUPPORTLASTERROR (Preserve Last Error Code for PInvoke Calls) linker option has been added.
  • 添加了 /CLRTHREADATTRIBUTE(设置 CLR 线程属性)链接器选项。/CLRTHREADATTRIBUTE (Set CLR Thread Attribute) linker option has been added.
  • 添加了 /CLRUNMANAGEDCODECHECK(添加 SupressUnmanagedCodeSecurityAttribute)链接器选项。/CLRUNMANAGEDCODECHECK (Add SupressUnmanagedCodeSecurityAttribute) linker option has been added.
  • 添加了 /ERRORREPORT(报告内部链接器错误)链接器选项。/ERRORREPORT (Report Internal Linker Errors) linker option has been added.
  • /EXETYPE 链接器选项已被移除。/EXETYPE linker option has been removed. 链接器不再支持创建 Windows 95 和 Windows 98 设备驱动程序。The linker no longer supports creating Windows 95 and Windows 98 device drivers. 使用适当的 DDK 来创建这些设备驱动程序。Use an appropriate DDK to create these device drivers. EXETYPE 关键字不再对模块定义文件有效。The EXETYPE keyword is no longer valid for module definition files.
  • 添加了 /FUNCTIONPADMIN(创建可热修补的映像)链接器选项。/FUNCTIONPADMIN (Create Hotpatchable Image) linker option has been added.
  • 使用 /clr 编译的模块现在支持 /LTCG 链接器选项。/LTCG linker option is now supported on modules compiled with /clr. 还更新了 /LTCG ,支持按配置优化。/LTCG has also been updated to support profile-guided optimizations.
  • 添加了 /MANIFEST(创建并行程序集清单)链接器选项。/MANIFEST (Create Side-by-Side Assembly Manifest) linker option has been added.
  • 添加了 /MANIFESTDEPENDENCY(指定清单依赖项)连接器选项。/MANIFESTDEPENDENCY (Specify Manifest Dependencies) linker option has been added.
  • 添加了 /MANIFESTFILE(命名清单文件)链接器选项。/MANIFESTFILE (Name Manifest File) linker option has been added.
  • /MAPINFO:LINES 链接器选项已被移除。/MAPINFO:LINES linker option has been removed.
  • 添加了 /NXCOMPAT(与数据执行保护兼容)链接器选项。/NXCOMPAT (Compatible with Data Execution Prevention) linker option has been added.
  • 添加了 /PGD(为按配置文件优化指定数据库)链接器选项。/PGD (Specify Database for Profile-Guided Optimizations) linker option has been added.
  • 添加了 /PROFILE(性能工具分析器)链接器选项。/PROFILE (Performance Tools Profiler) linker option has been added.
  • /SECTION(指定节属性)链接器选项现在支持属性求反,而不再支持 L 或 D(与 VxD 相关)属性。/SECTION (Specify Section Attributes) linker option now supports attribute negation and no longer supports the L or D (VxD-related) attributes.
  • 编译器和链接器中的 Unicode 支持Unicode Support in the Compiler and Linker
  • /VERBOSE(打印进度消息)链接器选项现在也接受 ICF 和 REF。/VERBOSE (Print Progress Messages) linker option now also accepts ICF and REF.
  • /VXD 链接器选项已被移除。/VXD linker option has been removed. 链接器不再支持创建 Windows 95 和 Windows 98 设备驱动程序。The linker no longer supports creating Windows 95 and Windows 98 device drivers. 使用适当的 DDK 来创建这些设备驱动程序。Use an appropriate DDK to create these device drivers. VXD 关键字不再对模块定义文件有效。The VXD keyword is no longer valid for module definition files.
  • /WS 链接器选项已被移除。/WS linker option has been removed. /WS 用于修改针对 Windows NT 4.0 的映像。/WS was used to modify images targeted for Windows NT 4.0. 可使用 IMAGECFG.exe -R 文件名代替 /WS。IMAGECFG.exe -R filename can be used instead of /WS. 可在 Windows NT 4.0 CD-ROM 上找到 IMAGECFG.exe,路径为 SUPPORT\DEBUG\I386\IMAGECFG.EXE。IMAGECFG.exe can be found on the Windows NT 4.0 CD-ROM in SUPPORT\DEBUG\I386\IMAGECFG.EXE.
  • /WX(将链接器警告视为错误)链接器选项现已记录。/WX (Treat Linker Warnings as Errors) linker option is now documented.

链接器实用工具的新增功能New Linker Utility Features

  • 添加了 /ALLOWISOLATION editbin 选项/ALLOWISOLATION editbin option had been added
  • 删除了 DESCRIPTION 模块定义文件语句。DESCRIPTION module definition file statement is removed. 链接器不再支持生成虚拟设备驱动程序。The linker no longer supports building virtual device drivers.
  • 在 bscmake.exe、dumpbin.exe、editbin.exe 和 lib.exe 中添加了 /ERRORREPORT 选项。/ERRORREPORT option has been added to bscmake.exe, dumpbin.exe, editbin.exe, and lib.exe.
  • 添加了 /LTCG lib 选项。/LTCG lib option has been added.
  • 添加了 /NXCOMPAT editbin 选项。/NXCOMPAT editbin option has been added.
  • 添加了 /RANGE dumpbin 选项。/RANGE dumpbin option has been added.
  • 添加了 /TLS dumpbin 选项。/TLS dumpbin option has been added.
  • /WS editbin 选项已被移除。/WS editbin option has been removed. /WS 用于修改针对 Windows NT 4.0 的映像。/WS was used to modify images targeted for Windows NT 4.0. 可使用 IMAGECFG.exe -R 文件名代替 /WS。IMAGECFG.exe -R filename can be used instead of /WS. 可在 Windows NT 4.0 CD-ROM 上找到 IMAGECFG.exe,路径为 SUPPORT\DEBUG\I386\IMAGECFG.EXE。IMAGECFG.exe can be found on the Windows NT 4.0 CD-ROM in SUPPORT\DEBUG\I386\IMAGECFG.EXE.
  • 添加了 /WX[:NO] lib 选项。/WX[:NO] lib option has been added.

NMAKE 的新增功能New NMAKE Features

  • 添加了 /ERRORREPORT。/ERRORREPORT has been added.
  • 添加了 /G。/G has been added.
  • 更新了预定义规则。The predefined rules have been updated.
  • 递归宏中记录的 $(MAKE) 宏现在提供 nmake.exe 的完整路径。The $(MAKE) macro, which is documented in Recursion Macros, now gives the full path to nmake.exe.

MASM 的新增功能New MASM Features

  • MASM 表达式现在为 64 位值。MASM expressions are now 64-bit values. 在早期版本中,MASM 表达式为 32 位值。In previous versions MASM expressions were 32-bit values.
  • 现在指令 __asm int 3 可使函数被编译到本机中。The instruction __asm int 3 now causes a function to be compiled to native.
  • ALIAS (MASM) 现已记录。ALIAS (MASM) is now documented.
  • 添加了 /ERRORREPORT ml.exe 和 ml64.exe 选项。/ERRORREPORT ml.exe and ml64.exe option is added.
  • .FPO 现已记录。.FPO is now documented.
  • Visual C++ 2005 中将不提供 H2INC.exe。H2INC.exe will not ship in Visual C++ 2005. 如果需要继续使用 H2INC,请使用 Visual C++ 早期版本中的 H2INC.exe。If you need to continue to use H2INC, use H2INC.exe from a previous version of Visual C++.
  • 添加了运算符 IMAGEREL。operator IMAGEREL has been added.
  • 添加了运算符 HIGH32。operator HIGH32 has been added.
  • 添加了运算符 LOW32。operator LOW32 has been added.
  • ml64.exe 是 x64 体系结构的 MASM 的一个版本。ml64.exe is a version of MASM for the x64 architecture. 它将 x64 .asm 文件组装到 x64 对象文件中。It assembles x64 .asm files into x64 object files. x64 编译器中不支持内联程序集语言。Inline assembly language is not supported in the x64 compiler. 为 ml64.exe (x64) 添加了以下 MASM 指令:The following MASM directives have been added for ml64.exe (x64):
  • .ALLOCSTACK.ALLOCSTACK
  • .ENDPROLOG.ENDPROLOG
  • .PUSHFRAME.PUSHFRAME
  • .PUSHREG.PUSHREG
  • .SAVEREG.SAVEREG
  • .SAVEXMM128.SAVEXMM128
  • .SETFRAME。此外,已用仅适用于 x64 的语法更新了 PROC 指令。.SETFRAME In addition, the PROC directive was updated with x64-only syntax.
  • 添加了 MMWORD 指令MMWORD directive has been added
  • /omf(ML.exe 命令行选项)现表示 /c。/omf (ML.exe command line option) now implies /c. ML.exe 不支持链接 OMF 格式对象。ML.exe does not support linking OMF format objects.
  • SEGMENT 指令现支持附加属性。The SEGMENT directive now supports additional attributes.
  • 添加了运算符 SECTIONREL。operator SECTIONREL has been added.
  • 添加了 XMMWORD 指令XMMWORD directive has been added

CRT 的新增功能New CRT Features

  • 添加了一些函数的安全版本。Secure versions of several functions have been added. 这些函数以更好的方式处理错误,并强制对缓冲区实施更严格的控制以避免常见的安全漏洞。These functions handle errors in a better way and enforce stricter controls on buffers to help avoid common security flaws. 新的安全版本由 _s 后缀标识。The new secure versions are identified by the _s suffix.
  • 已弃用许多函数现有的安全性较低的版本。Existing less secure versions of many functions have been deprecated. 若要禁用弃用警告,请定义 _CRT_SECURE_NO_WARNINGS。To disable the deprecation warnings, define _CRT_SECURE_NO_WARNINGS.
  • 许多现有函数现在会验证其参数,并在传递了无效参数时调用无效参数处理程序。Many existing functions now validate their parameters and invoke the invalid parameter handler when an invalid parameter is passed.
  • 许多现有函数现在在过去没有设置 errno 的地方对其进行了设置。Many existing functions now set errno where they did not before.
  • 添加了具有整数类型的 typedef errno_t。The typedef errno_t with type integer was added. 每当函数返回类型或参数处理来自 errno 的错误代码时,就会使用 errno_t。errno_t is used whenever a function return type or parameter deals with error codes from errno. errno_t 替换 errcode。errno_t replaces errcode.
  • 依赖于区域设置的函数现在有了新的版本,这些版本将区域设置作为参数,而不是使用当前的区域设置。Locale-dependent functions now have versions which take the locale as a parameter rather than using the current locale. 这些新的函数具有 _l 后缀。These new functions have the _l suffix. 添加了一些新函数,用于区域设置对象。Several new functions were added to work with locale objects. 新的函数包括 _get_current_locale、_create_locale 和 _free_locale。New functions include _get_current_locale, _create_locale and _free_locale.
  • 添加了新函数,以支持锁定和解锁文件句柄。New functions were added to support locking and unlocking file handles.
  • _spawn 系列函数不会像在早期版本中那样,在成功时将 errno 重置为零。The _spawn family of functions does not reset errno to zero on success, as it did in previous versions.
  • 提供了可用于指定参数使用顺序的 printf 系列函数版本。Versions of the printf family of functions that allow you to specify the order in which the arguments are used are available.
  • 现已支持 Unicode 文本格式。Unicode is now a supported text format. 函数 _open 支持 _O_TEXTW、_O_UTF8 和 _O_UTF16 属性。The function _open supports _O_TEXTW, _O_UTF8 and _O_UTF16 attributes. fopen 函数支持指定 Unicode 格式的“ccs=ENCODING”方法。The fopen function supports the "ccs=ENCODING" method of specifying a Unicode format.
  • 现在提供以托管代码 (MSIL) 生成的 CRT 库的新版本,可在用 /clr(公共语言运行时编译)选项进行编译时使用。A new version of the CRT libraries built in managed code (MSIL) is now available and is used when compiling with the /clr (Common Language Runtime Compilation) option.
  • _fileinfo 已被移除。_fileinfo has been removed.
  • time_t 的默认大小现在为 64 位,可以将 time_t 和一些时间函数的范围扩展到 3000 年。The default size for time_t is now 64 bits, which expands the range of time_t and several of the time functions out to the year 3000.
  • CRT 现在支持按每个线程进行区域设置。The CRT now supports setting the locale on a per thread basis. 添加了 _configthreadlocale 函数以支持此功能。The function _configthreadlocale was added to support this feature.
  • 添加了 _statusfp2 和 __control87_2 函数,以允许对 x87 和 SSE2 浮点处理器上的浮点控制字进行访问和控制。The _statusfp2 and __control87_2 functions were added to allow access to and control of the floating point control word on both the x87 and SSE2 floating point processor.
  • 添加了 _mkgmtime 和 _mkgmtime64 函数,以支持将时间 (struct tm) 转换为格林威治标准时间 (GMT)。The_mkgmtime and _mkgmtime64 functions were added to provide support for converting times (struct tm) to Greenwich Mean Time (GMT).
  • 对 swprintf 和 vswprintf 进行了更改以更好地符合标准。Changes were made to swprintf and vswprintf to better conform with the standard.
  • 新的头文件 INTRIN.H 提供了某些内部函数的原型。A new header file, INTRIN.H, provides prototypes for some intrinsic functions.
  • fopen 函数现在具有一个 N 属性。The fopen function now has an N attribute.
  • _open 函数现在具有一个 _O_NOINHERIT 属性。The _open function now has an _O_NOINHERIT attribute.
  • atoi 函数现在会在溢出时返回 INT_MAX 并将 errno 设置为 ERANGE。The atoi function now returns INT_MAX and sets errno to ERANGE on overflow. 早期版本中未定义溢出行为。In previous versions, the overflow behavior was undefined.
  • printf 系列函数支持根据 ANSI C99 标准使用格式类型说明符 %a 和 %A 实现的十六进制浮点输出。The printf family of functions supports hexadecimal floating point output implemented according to the ANSI C99 standard using the format type specifiers %a and %A.
  • printf 系列现在支持“ll”(long long) 大小前缀。The printf family now supports the "ll" (long long) size prefix.
  • 优化了 _controlfp 函数,以提供更好的性能。The _controlfp function has been optimized for better performance.
  • 添加了某些函数的调试版本。Debug versions of some functions have been added.
  • 添加了 _chgsignl 和 _cpysignl(long double 版本)。Added _chgsignl and _cpysignl (long double versions).
  • 将 _locale_t 类型添加到了类型表。Added _locale_t type to type table.
  • 添加了新的 _countof Macro 宏,用于计算数组中的元素数量。New macro _countof Macro added for computing number of elements in an array.
  • 在每个函数主题中,添加了一节有关 .NET Framework 等效项的内容。In each function topic, a section on .NET Framework equivalents has been added.
  • 一些字符串函数现在可以选择在输出缓冲区太小时截断字符串,而不会失败;请参阅“_TRUNCATE”。Several string functions now have the option of truncating strings rather than failing when output buffers are too small; see _TRUNCATE.
  • _set_se_translator 现在需要使用 /EHa 编译器选项。_set_se_translator now requires the use of the /EHa compiler option.
  • 现在,在 /Za 下(对于 C 代码)和手动设置 STDC(对于 C++ 代码)时,fpos_t 会变为 int64。fpos_t is now __int64 under /Za (for C code) and when __STDC is set manually (for C++ code). 以前它是一个结构。It used to be a struct.
  • _CRT_DISABLE_PERFCRIT_LOCKS 可以提高单线程程序的 I/O 性能。_CRT_DISABLE_PERFCRIT_LOCKS can improve the I/O performance of single-threaded programs.
  • 在对符合 ISO C++ 名称的优选中,弃用了 POSIX 名称(例如,使用 _getch 而不是 getch)。POSIX names have been deprecated in favor of ISO C++ conformant names (for example, use _getch rather than getch).
  • 新的链接选项 .obj 文件可用于纯模式New link options .obj files are available for pure mode
  • _recalloc 合并了 realloc 和 calloc 的功能。_recalloc combines features of realloc and calloc.

Visual Studio 2003 中 C++ 的新增功能What's New for C++ in Visual Studio 2003

编译器Compiler

  • 介绍如何在早期版本的运行时上运行用当前版本的编译器生成的 Managed Extensions for C++ 应用程序。Information on how to run a Managed Extensions for C++ application built with the current version's compiler on a previous version of the runtime.
  • Managed Extensions for C++ 的常见问题解答。Managed Extensions for C++ Frequently Asked Questions.
  • 添加了一个演练,演示如何移植现有本机应用程序以使用 Managed Extensions for C++:“演练:移植现有本机 C++ 应用程序,使其能与 .NET Framework 组件进行交互”。A walkthrough has been added showing how to port an existing, native application to use Managed Extensions for C++: Walkthrough: Porting an Existing Native C++ Application to Interoperate with .NET Framework Components.
  • 现在可以在值类型的方法上创建委托。You can now create a delegate on a method of a value type.
  • Visual C++ .NET 2003 已极大地增强了编译器与 C++ 标准的符合性。The compiler's conformance with the C++ standard has been significantly enhanced for Visual C++ .NET 2003.
  • 添加了 /arch 编译器选项。/arch compiler option is added.
  • 已弃用 /Gf,并将从 Visual C++ 的下一个版本中删除。/Gf is deprecated and will be removed in the next version of Visual C++.
  • 添加了 /G7 编译器选项。/G7 compiler option is added.
  • 已增强 /GS 编译器选项以帮助保护本地变量,防止直接缓冲区溢出。The /GS compiler option has been enhanced to help protect local variables from direct buffer overruns.
  • /noBool 编译器选项已被移除。The /noBool compiler option has been removed. 编译器现在允许 bool 在 C++ 源代码文件中仅作为关键字(而不是标识符)出现。The compiler now allows bool to appear only as a keyword (and not an identifier) in a C++ source code file.
  • long long 类型现在可用作 __int64 的 typedef。请注意,在 CRT 中还不支持 longlong。The long long type is now available as a typedef of __int64 Note that there is not yet support for long long in the CRT.
  • /Zm 编译器选项现在指定预编译标头内存分配限制。The /Zm compiler option now specifies the precompiled header memory allocation limit.
  • _InterlockedCompareExchange 内部函数现已记录。_InterlockedCompareExchange intrinsic now documented.
  • _InterlockedDecrement 内部函数现已记录。_InterlockedDecrement intrinsic now documented.
  • _InterlockedExchange 内部函数现已记录。_InterlockedExchange intrinsic now documented.
  • _InterlockedExchangeAdd 内部函数现已记录。_InterlockedExchangeAdd intrinsic now documented.
  • _InterlockedIncrement 内部函数现已记录。_InterlockedIncrement intrinsic now documented.
  • 添加了 _ReadWriteBarrier 内部函数。_ReadWriteBarrier intrinsic added.

特性Attributes

  • implements 属性现已记录。implements attribute is now documented.

链接器的功能Linker features

添加了以下链接器开关:The following linker switches have been added:

  • /ASSEMBLYDEBUG/ASSEMBLYDEBUG
  • /ASSEMBLYLINKRESOURCE/ASSEMBLYLINKRESOURCE
  • DELAYSIGNDELAYSIGN
  • /KEYFILE/KEYFILE
  • /KEYCONTAINER/KEYCONTAINER
  • /SAFESEH/SAFESEH

MASMMASM

天界了 .SAFESEH 指令和 /safeseh ml.exe 选项。The .SAFESEH directive and /safeseh ml.exe option were added.

请参阅See Also

Visual C++ 移植和升级指南Visual C++ Porting and Upgrading Guide