std::unique_ptr<Json::CharReader> jsonReader{ readerBuilder.newCharReader()};
时间: 2024-05-19 19:12:32 浏览: 229
This line of code creates a new `std::unique_ptr` object named `jsonReader`, which is a smart pointer that owns and manages a dynamically allocated `Json::CharReader` object. The `newCharReader()` function is called on an instance of `Json::CharReaderBuilder`, which returns a pointer to a new `Json::CharReader` object. The `std::unique_ptr` takes ownership of this object and will automatically delete it when it goes out of scope.
相关问题
vector<unique_ptr>
vector<unique_ptr>是一个存储unique_ptr的动态数组,其中每个元素都是一个unique_ptr对象,每个对象都拥有独特的所有权。unique_ptr是一个智能指针,它提供了对动态分配对象的所有权和管理。当unique_ptr超出范围时,它将自动删除其所拥有的对象。下面是一个vector<unique_ptr>的例子:
```cpp
#include <iostream>
#include <vector>
#include <memory>
int main() {
std::vector<std::unique_ptr<int>> vec;
vec.push_back(std::make_unique<int>(1));
vec.push_back(std::make_unique<int>(2));
vec.push_back(std::make_unique<int>(3));
for (const auto& ptr : vec) {
std::cout << *ptr << " ";
}
// 输出:1 2 3
return 0;
}
```
阅读全文