我试图理解一个移动构造函数,
通常在复制对象时调用复制构造函数
当我不提供移动构造函数时会发生什么,
但是当我添加一个移动构造函数时,它被调用而不是我的复制构造函数,
这是我的代码:
#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)
编译器是否尝试优化我的代码并选择更好的方法?
我想要使用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库时会出现此错误
任何的想法 ?