C++的vector和外界共用一个对象而避免发生对象拷贝?

1. 
#include <vector>
#include <iostream>
#include <functional>

int main() {
    int a = 10;
    std::vector<std::reference_wrapper<int>> v;
    v.emplace_back(std::ref(a));
    v[0]--;
    std::cout << a << "\n";
}

2. 直接用指针 vector<int*>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注