1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include <memory> #include <vector> #include <iostream>
using VecUL = std::vector<unsigned long>;
void func(std::shared_ptr<VecUL> datas) { auto count = datas.use_count(); std::cout << count << "\n"; for (auto &data : *datas) { data++; } }
void func(std::shared_ptr<unsigned int> data) { auto count = data.use_count(); std::cout << count << "\n"; }
int main() { auto * p0 = new unsigned int{34}; std::shared_ptr<unsigned int> ptr{p0}; auto count = ptr.use_count(); std::cout << count << "\n"; *ptr = 65535; func(ptr);
auto *p1 = new VecUL{0xff, 0xffff, 0xffffff, 0xffffffff}; std::shared_ptr<VecUL> ptr1{p1}; auto count1 = ptr1.use_count(); std::cout << count1 << "\n"; ptr1->push_back(65535); ptr1->push_back(65535); ptr1->push_back(65535); ptr1->push_back(65535); ptr1->push_back(65535); func(ptr1);
return 0; }
|