小编lin*_*uxD的帖子

为什么移动构造函数而不是复制构造函数

我试图理解一个移动构造函数,

通常在复制对象时调用复制构造函数

当我不提供移动构造函数时会发生什么,

但是当我添加一个移动构造函数时,它被调用而不是我的复制构造函数,

这是我的代码:

#include <iostream>
#include <vector>

using namespace std;

struct A
{
    A()
    {
        cout << "A's constructor" << endl;
    }

    A(const A& rhs)
    {
        cout << "A's copy constructor" << endl;
    }

    A(A&& rhs)
    {
        cout << "A's move constructor" << endl;
    }
};

int main() {

    vector<A> v;

    cout << "==> push_back A():";
    v.push_back(A());

    cout << "==> push_back A():" << endl;
    v.push_back(A());

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译器是否尝试优化我的代码并选择更好的方法?

c++ c++11

0
推荐指数
1
解决办法
822
查看次数

错误:'array':模糊符号

我想要使​​用boost数组

但是我收到了这个错误:

错误:'array':模糊符号

这是我的代码:

#include <iostream>
#include <boost/array.hpp>
#include <boost/regex.hpp>

using namespace boost;

using namespace std;



int main(int argc, char* argv[])
{
    array<int, 10> a{3};

    cout << "a[0]= " << a[0];

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我包含boost库时会出现此错误

任何的想法 ?

c++ boost

-3
推荐指数
1
解决办法
1695
查看次数

标签 统计

c++ ×2

boost ×1

c++11 ×1