gpt4 book ai didi

c++ - 将 auto_ptr 转换为 void 指针

转载 作者:太空狗 更新时间:2023-10-29 21:01:01 25 4
gpt4 key购买 nike

我正在尝试以下列方式将 auto_ptr 转换为 void 指针:

void *AM::This2Ctx(std::auto_ptr<AMContext> data)
{
return reinterpret_cast<void *>(data);
}

但我一直收到编译错误:

error: invalid cast from type std::auto_ptr<AMContext> to type void*

如何才能正确完成此转换?以及如何以相反的方式使用它?

最佳答案

使用.get()访问 auto-ptr 持有的指针:

reinterpret_cast<void *>(data.get());
~~~~~~

此外,auto_ptr已弃用,请使用 unique_ptr相反。

关于c++ - 将 auto_ptr 转换为 void 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19887833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com