ICode9

精准搜索请尝试: 精确搜索
  • c-引发异常时不调用Move构造函数2019-10-11 22:10:02

    我有一个变量,它会累积当前异常,并且在抛出当前异常时需要清除该变量(这样就不会再次报告相同的错误).问题是抛出std :: move(ex);不调用move构造函数(这将清除ex),而是调用一个复制构造函数(这样ex也会保留已引发的错误). MVCE遵循: #include <iostream> #include <stdexcept> #in

  • c – 为什么编译器需要复制构造函数,需要并且移动一个并且不使用它们中的任何一个?2019-10-07 11:06:49

    我已经尝试过问这个问题,但我还不够清楚.所以这是另一个尝试.我对我的英语很抱歉;) 我们来看看代码: #include <iostream> #include <memory> using namespace std; struct A { unique_ptr<int> ref; void printRef() { if (ref.get()) cout<<"i="<

  • 为什么C默认不移动构造右值引用?2019-10-02 00:06:12

    参见英文答案 > Rvalue Reference is Treated as an Lvalue?                                    4个 >            Lvalue reference constructor is called instead of rvalue reference constructor            

  • c – Visual Studio 2017是否需要显式移动构造函数声明?2019-09-30 17:06:19

    下面的代码可以使用Visual Studio 2015成功编译,但使用Visual Studio 2017失败.Visual Studio 2017报告: error C2280: “std::pair::pair(const std::pair &)”: attempting to reference a deleted function 码 #include <unordered_map> #include <memory> struct Node {

  • C不通过取消注释move运算符进行编译2019-08-29 01:05:45

    我有以下代码: template <typename T> struct X { X() : x(5) {} template <template <typename> class S> X(const S<T> & y) : x(y.x) {} // Uncomment and it does not compile anymore // X(X&& z) : x(z.x) {}

  • C:存储复制操作不合理或不可能的资源2019-08-25 15:13:11

    我想编写一个ContentManager类,为游戏加载和维护不同类型的资产(与XNA’s ContentManager比较). 我的头文件如下所示: class ContentManager { public: ContentManager(Direct3D& d3d, const std::string& rootDirectory = "Resource"); ~ContentManager(); template<typenam

  • c – delete / default关键字是否将相应的方法标记为用户定义?2019-08-24 00:05:15

    我有以下代码: #include <iostream> class B{ public: //this should all be generated by default but //throwing them in here just to be sure B() = default; B(const B& b) = default; B& operator=(const B& b) = default; B(B&

  • c – 为什么移动构造函数会影响is_assignable?2019-07-31 02:06:23

    刚刚来自is_assignable and std::unique_ptr. @Angew告诉我,因为std :: unique_ptr< int,do_nothing>和std :: unique_ptr< int>是不同的类型,所以static_assert(不是std :: is_assignable< std :: unique_ptr< int>,std :: unique_ptr< int,do_nothing>> :: value,

  • 当我初始化一个C容器(如std :: list)时,复制构造函数是否被调用?2019-07-30 00:06:16

    当我初始化STL容器时,例如列表<矢量<炭&GT &GT使用例如my_list.push_back(vector< char>(5000,’T’))是在构建后复制的吗?或者编译器是否调用list<中的构造函数?矢量<炭&GT &GT本身?解决方法:在C 03中,push_back被定义为void push_back(const T& x);.这意味着您正在构建一个向量,并且

  • c – 移动语义如何保留临时变量的数据?2019-07-27 18:08:25

    我正在读这篇文章:What are move semantics? 请注意,移动构造函数的帖子中给出的示例是: string(string&& that) { data = that.data; that.data = nullptr; } 当我们使用字符串a(x y)来构造一个新字符串时,我发现它很混乱.由于x y的结果是一个临时变量,它很快就会被破坏

  • c – 当我什么都不移动时,为什么clang会抱怨删除的动作?2019-07-27 03:07:49

    前提: #include <iostream> using namespace std; class ABC { public: ABC() { cout << "Default constructor ..\n"; } ABC(const ABC& a) { cout << "In copy constrcutor ..\n"; } ABC(ABC&

  • c – 为什么显式调用base move构造函数实际调用基类复制构造函数?2019-07-26 04:06:34

    参见英文答案 > Move constructor on derived object                                    2个 我试图通过派生类移动ctor显式调用基类移动ctor,但是,惊讶!,实际上调用基类复制ctor而不是基类移动ctor. 我在一个对象上使用std :: move()函数,以

  • 在C中移动构造函数和复制构造函数2019-07-24 11:07:15

    我的理解是,当我们从函数返回本地对象时,如果它存在,则调用移动构造函数.但是,我遇到了调用复制构造函数的情况,如下面的函数foo2()中所示.为什么会这样? #include <cstdio> #include <memory> #include <thread> #include <chrono> class tNode { public: tNode(int b = 10)

  • 试图使用c move构造函数……并失败2019-07-22 18:08:35

    当我以为我理解std :: move和移动构造函数的时候,我试着编写一些单元测试,实际测试某些类的移动构造函数… 令我惊讶的是,我发现,我无法想出构建实际调用移动构造函数的代码的方法.更糟糕的是,我甚至无法在移动构造函数的主体中设置断点(在VS2013社区版,调试,64位构建中). 想知道这

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有