gpt4 book ai didi

c++11 - std::move-如何警告程序员不要使用* move 自*对象

转载 作者:行者123 更新时间:2023-12-02 11:29:34 27 4
gpt4 key购买 nike

假设有一个这样的函数:

int * func()
{
std::unique_ptr<int> ptr(new int(3));
//Few more lines of code

//then one function added where programmer writes like some thing

SOME_OTHER_FUNC(std::move(ptr));

return ptr.get();
}



void SOME_OTHER_FUNC(std::unique_ptr<int> arg_ptr)
{
}

有没有办法警告程序员避免使用 std::move 出现此类错误?这不仅仅涉及 unique_ptr,也适用于其他对象。

当我们不恰本地使用移自对象时,是否有任何机制可以生成警告?

最佳答案

std::move 警告。如果你的程序员不明白这一点,你就必须更好地教育他们。如果函数太长以至于程序员可以合理地忽略 move ,则需要重构函数以使其更短。

关于c++11 - std::move-如何警告程序员不要使用* move 自*对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39876988/

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