相关疑难解决方法(0)

在std :: vector上调整大小不会调用移动构造函数

我一直在使用std :: vector来理解何时构造,破坏,复制构造和移动构造的对象.为此,我编写了以下程序

#include <iostream>
#include <vector>

class Test {
public:
    Test() {
        std::cout << "Constructor called for " << this << std::endl;
    }
    Test(const Test& x) {
        std::cout << "Copy Constructor called for " << this << std::endl;
    }
    Test(Test&& x) {
        std::cout << "Move Constructor called for " << this << std::endl;
    }
    ~Test() {
        std::cout << "Destructor called for " << this << std::endl;
    }
};

int main() {
    std::vector<Test> a( 1 );
    a.resize(3);

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

c++ move vector c++11

8
推荐指数
1
解决办法
1118
查看次数

标签 统计

c++ ×1

c++11 ×1

move ×1

vector ×1