sách gpt4 ăn đã đi

c++ - auto 关键字和 smartpointers 一起?

In lại 作者:搜寻专家 更新时间:2023-10-31 00:27:15 30 4
mua khóa gpt4 giày nike

我可以:

auto o1 = new Content;

但不能:

std::shared_ptr o1(new Content);
std::unique_ptr o1(new Content);

我该怎么办?

câu trả lời hay nhất

你可以像这样使用make_shared/make_unique:

auto o1 = std::make_shared(); // Pass any arguments here as you would normally.
auto o2 = std::make_unique(); // Pass any arguments here as you would normally.

这些函数将所有参数转发给(在本例中)Content 的构造函数,您可以使用 tự động 并且您只需编写一次类型。

关于c++ - auto 关键字和 smartpointers 一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49801020/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress