gpt4 book ai didi

c++ - c++ 旧功能的更好替代方案?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:09:08 25 4
gpt4 key购买 nike

c++ 已经走了很长一段路,它有很多特性可以用 n 种方法来完成同样的任务。您认为应该避免哪些功能并列出更好的替代方案。

Like use SmartPointers in places of pointers

最佳答案

避免 malloc,使用 new。

避免使用 memcpy,使用复制构造函数。

避免 #defines , 使用 const

Avoid (C-style) casts , use static_cast<C++>( style casts ) .

避免宏,使用模板。

如果可以使用预增量,请避免使用后增量。

避免 new,使用值类型的集合,让集合处理内存管理。

避免指向新对象,使用boost::scoped_ptrboost::shared_ptr.

避免编写自己的代码来遍历集合,使用 <algorithm>

避免重新发明轮子,看看boost是否有你需要的。

避免使用“char * name”来存储字符串,使用 std::string。

Avoid using namespace foo , use using foo::bar .

避免“静态(内部链接)声明”使用未命名的命名空间。

关于c++ - c++ 旧功能的更好替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/819481/

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