构建 shared_ptr 时遇到问题 [英] Trouble constructing shared_ptr

查看:68
本文介绍了构建 shared_ptr 时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是智能指针的新手,我正在努力解决每一个绊脚石.

I'm new to smart pointers, and I'm in the process of hitting every stumbling block.

我有一个结构texture_t:

struct texture_t
{
    hash32_t hash;
    uint32_t width;
    uint32_t height;
    uint32_t handle;
};

当我尝试使用此行创建此结构的 shared_ptr 时:

When I try and make a shared_ptr of this struct using this line:

auto texture_shared_ptr = std::make_shared<texture_t>(new texture_t());

我收到此错误:

error C2664: 'mandala::texture_t::texture_t(const mandala::texture_t &)' : cannot convert parameter 1 from 'mandala::texture_t *' to 'const mandala::texture_t &'

这个错误来自哪里,我该如何避免?

Where is this error coming from and how can I avoid it?

推荐答案

您不应该将 new ed 指针传递给 std::make_shared.您只需要传递可以构造 texture_t 的参数.

You are not supposed to pass a newed pointer to std::make_shared. You just need to pass arguments from which a texture_t can be constructed to it.

这篇关于构建 shared_ptr 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆