<tfoot id='0YFvf'></tfoot>
  • <legend id='0YFvf'><style id='0YFvf'><dir id='0YFvf'><q id='0YFvf'></q></dir></style></legend>

      <small id='0YFvf'></small><noframes id='0YFvf'>

      <i id='0YFvf'><tr id='0YFvf'><dt id='0YFvf'><q id='0YFvf'><span id='0YFvf'><b id='0YFvf'><form id='0YFvf'><ins id='0YFvf'></ins><ul id='0YFvf'></ul><sub id='0YFvf'></sub></form><legend id='0YFvf'></legend><bdo id='0YFvf'><pre id='0YFvf'><center id='0YFvf'></center></pre></bdo></b><th id='0YFvf'></th></span></q></dt></tr></i><div id='0YFvf'><tfoot id='0YFvf'></tfoot><dl id='0YFvf'><fieldset id='0YFvf'></fieldset></dl></div>
      • <bdo id='0YFvf'></bdo><ul id='0YFvf'></ul>

      1. 应该 std::unique_ptr<void>被允许

        时间:2023-05-23

        <tfoot id='Sn4ZT'></tfoot>
            <bdo id='Sn4ZT'></bdo><ul id='Sn4ZT'></ul>

            <legend id='Sn4ZT'><style id='Sn4ZT'><dir id='Sn4ZT'><q id='Sn4ZT'></q></dir></style></legend>
            • <i id='Sn4ZT'><tr id='Sn4ZT'><dt id='Sn4ZT'><q id='Sn4ZT'><span id='Sn4ZT'><b id='Sn4ZT'><form id='Sn4ZT'><ins id='Sn4ZT'></ins><ul id='Sn4ZT'></ul><sub id='Sn4ZT'></sub></form><legend id='Sn4ZT'></legend><bdo id='Sn4ZT'><pre id='Sn4ZT'><center id='Sn4ZT'></center></pre></bdo></b><th id='Sn4ZT'></th></span></q></dt></tr></i><div id='Sn4ZT'><tfoot id='Sn4ZT'></tfoot><dl id='Sn4ZT'><fieldset id='Sn4ZT'></fieldset></dl></div>
                <tbody id='Sn4ZT'></tbody>
                1. <small id='Sn4ZT'></small><noframes id='Sn4ZT'>

                  本文介绍了应该 std::unique_ptr<void>被允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这是一个非常简单的问题.考虑以下代码:

                  This is a very simple question. Consider the following code:

                  #include <iostream>
                  #include <memory>
                  
                  typedef std::unique_ptr<void> UniqueVoidPtr;
                  
                  int main() {
                      UniqueVoidPtr p(new int);
                      return 0;
                  }
                  

                  使用 cygwin (g++ 4.5.3) 和以下命令编译 g++ -std=c++0x -o prog file.cpp 工作得很好.但是,使用 Microsoft 编译器(VS 2010 或 2013)进行编译时出现此错误:

                  Compiling with cygwin (g++ 4.5.3) with the following command g++ -std=c++0x -o prog file.cpp works just fine. However, compiling with the microsoft compiler (either VS 2010 or 2013) I get this error:

                  C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDEmemory(2067) : error C2070: 'void': illegal sizeof operand
                          C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDEmemory(2066) : while compiling class template member function 'void std::default_delete<_Ty>::operator ()(_Ty *) const'
                          with
                          [
                              _Ty=void
                          ]
                          C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDE	ype_traits(650) : see reference to class template instantiation 'std::default_delete<_Ty>' being compiled
                          with
                          [
                              _Ty=void
                          ]
                          C:Program Files (x86)Microsoft Visual Studio 10.0VCINCLUDEmemory(2193) : see reference to class template instantiation 'std::tr1::is_empty<_Ty>' being compiled
                          with
                          [
                              _Ty=std::default_delete<void>
                          ]
                          foo1.cpp(7) : see reference to class template instantiation 'std::unique_ptr<_Ty>' being compiled
                          with
                          [
                              _Ty=void
                          ]
                  

                  这是预期的吗?我正在写一个类,我想在类中拥有一个唯一的指针.在尝试为类计算移动构造函数的语义时,我遇到了这个问题(我假设是因为我最终正确编码了移动构造函数:即其他错误已修复).

                  Is this expected? I'm writing a class where I wanted to have a unique pointer in the in the class. While trying to work out the semantics of a move constructor for the class, I ran into this (I assume because I finally got my move constructor coded correctly: i.e. the other errors were fixed).

                  推荐答案

                  MSVC 是对的,而 GCC 是错的:

                  MSVC is right while GCC is wrong:

                  标准(3.9/5):

                  不完全定义的对象类型和void类型是不完全类型

                  Incompletely-defined object types and the void types are incomplete types

                  标准(20.7.1.1.2/4):

                  Standard(20.7.1.1.2/4):

                  如果 T 是不完整类型,则程序格式错误

                  If T is an incomplete type, the program is ill-formed

                  这篇关于应该 std::unique_ptr<void>被允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:`struct X typedef` 与 `typedef struct X` 的含义是什么? 下一篇:有条件地替换字符串中的正则表达式匹配项

                  相关文章

                  最新文章

                2. <tfoot id='SfjpI'></tfoot>
                3. <legend id='SfjpI'><style id='SfjpI'><dir id='SfjpI'><q id='SfjpI'></q></dir></style></legend>

                    1. <i id='SfjpI'><tr id='SfjpI'><dt id='SfjpI'><q id='SfjpI'><span id='SfjpI'><b id='SfjpI'><form id='SfjpI'><ins id='SfjpI'></ins><ul id='SfjpI'></ul><sub id='SfjpI'></sub></form><legend id='SfjpI'></legend><bdo id='SfjpI'><pre id='SfjpI'><center id='SfjpI'></center></pre></bdo></b><th id='SfjpI'></th></span></q></dt></tr></i><div id='SfjpI'><tfoot id='SfjpI'></tfoot><dl id='SfjpI'><fieldset id='SfjpI'></fieldset></dl></div>

                        <bdo id='SfjpI'></bdo><ul id='SfjpI'></ul>

                      <small id='SfjpI'></small><noframes id='SfjpI'>