草庐IT

UINT_PTR

全部标签

c++ - 为什么 unique_ptr<T>(T*) 是显式的?

以下函数无法编译:std::unique_ptrfoo(){int*answer=newint(42);returnanswer;}std::unique_ptrbar(){returnnewint(42);}我觉得这有点不方便。制作std::unique_ptr(T*)的理由是什么?明确的? 最佳答案 您不希望托管指针隐式获取原始指针的所有权,因为这可能会导致未定义的行为。考虑一个函数voidf(int*);和一个电话int*p=newint(5);f(p);deletep;.现在假设有人重构f采用托管指针(任何类型)并允许隐式转

c++ - "Uint32"、"int16"等;它们是标准的 C++ 吗?

我对c++很陌生,但我已经掌握了基础知识。我在阅读其他人的代码时遇到了“Uint32”(各种大写形式)和类似数据类型的使用,但我找不到任何提及它们的文档。我知道“Uint32”是一个32位的无符号整数,但我的编译器没有。我正在使用visualc++express,它无法识别任何形式的它。是否有一些编译器默认读取这些数据类型,或者这些程序员将它们自己声明为类或#define常量?我可以看到使用它们来准确了解整数的长度,因为正常声明似乎因系统而异。使用它们还有其他优点或缺点吗? 最佳答案 Unix平台在stdint.h中定义这些类型,这

c++ - "Uint32"、"int16"等;它们是标准的 C++ 吗?

我对c++很陌生,但我已经掌握了基础知识。我在阅读其他人的代码时遇到了“Uint32”(各种大写形式)和类似数据类型的使用,但我找不到任何提及它们的文档。我知道“Uint32”是一个32位的无符号整数,但我的编译器没有。我正在使用visualc++express,它无法识别任何形式的它。是否有一些编译器默认读取这些数据类型,或者这些程序员将它们自己声明为类或#define常量?我可以看到使用它们来准确了解整数的长度,因为正常声明似乎因系统而异。使用它们还有其他优点或缺点吗? 最佳答案 Unix平台在stdint.h中定义这些类型,这

c++ - 表达式 "(ptr == 0) != (ptr == (void*)0)"真的可以吗?

我在aforumthread中阅读了此声明链接到inacommentby@jsantander:Keepinmindthatwhenyouassignorcompareapointertozero,thereissomespecialmagicthatoccursbehindthescenestousethecorrectpatternforthegivenpointer(whichmaynotactuallybezero).Thisisoneofthereasonswhythingslike#defineNULL(void*)0areevil–ifyoucompareachar*to

c++ - 表达式 "(ptr == 0) != (ptr == (void*)0)"真的可以吗?

我在aforumthread中阅读了此声明链接到inacommentby@jsantander:Keepinmindthatwhenyouassignorcompareapointertozero,thereissomespecialmagicthatoccursbehindthescenestousethecorrectpatternforthegivenpointer(whichmaynotactuallybezero).Thisisoneofthereasonswhythingslike#defineNULL(void*)0areevil–ifyoucompareachar*to

c++ - 在 Unix 和 Windows 上都可以使用的 C 中 64 位整数(uint64_t)的 atoi 等价物是什么?

我正在尝试将64位整数字符串转换为整数,但我不知道该使用哪一个。 最佳答案 使用strtoull如果你有它或_strtoui64()与VisualStudio。unsignedlonglongstrtoull(constchar*restrictstr,char**restrictendptr,intbase);/*IamsureMShadagoodreasonnottonameit"strtoull"or*"_strtoull"atleast.*/unsigned__int64_strtoui64(constchar*nptr,c

c++ - 在 Unix 和 Windows 上都可以使用的 C 中 64 位整数(uint64_t)的 atoi 等价物是什么?

我正在尝试将64位整数字符串转换为整数,但我不知道该使用哪一个。 最佳答案 使用strtoull如果你有它或_strtoui64()与VisualStudio。unsignedlonglongstrtoull(constchar*restrictstr,char**restrictendptr,intbase);/*IamsureMShadagoodreasonnottonameit"strtoull"or*"_strtoull"atleast.*/unsigned__int64_strtoui64(constchar*nptr,c

c++ - 在 C++11 中将对象的所有权从一个 unique_ptr 转移到另一个 unique_ptr?

在C++11中,我们可以使用std::move()将一个对象的所有权转移到另一个unique_ptr。所有权转移后,让出所有权的智能指针变为null,get()返回nullptr.std::unique_ptrp1(newint(42));std::unique_ptrp2=std::move(p1);//Transferownership在将所有权转移到另一个unique_ptr时,这在哪些情况下有用? 最佳答案 以下情况涉及从一个unique_ptr转移所有权另一个:从函数返回,并作为参数传递给构造函数等函数。假设你有一些多态类

c++ - 在 C++11 中将对象的所有权从一个 unique_ptr 转移到另一个 unique_ptr?

在C++11中,我们可以使用std::move()将一个对象的所有权转移到另一个unique_ptr。所有权转移后,让出所有权的智能指针变为null,get()返回nullptr.std::unique_ptrp1(newint(42));std::unique_ptrp2=std::move(p1);//Transferownership在将所有权转移到另一个unique_ptr时,这在哪些情况下有用? 最佳答案 以下情况涉及从一个unique_ptr转移所有权另一个:从函数返回,并作为参数传递给构造函数等函数。假设你有一些多态类

c++ - c++11 中的 intrusive_ptr

C++11是否有与boost::intrusive_ptr等价的东西?我的问题是我的C++代码有一个C风格的界面。接口(interface)的两端都可以使用C++,但出于兼容性原因,需要公开C接口(interface)。我不能使用std::shared_ptr因为我必须通过两个(或更多)智能指针来管理对象。我无法用boost::intrusive_ptr之类的方法找到解决方案。 最佳答案 Doesc++11havesomethingequivalenttoboost::intrusive_ptr?没有。它确实有std::make_s