jjzjj

reinterpret

全部标签

c++ - Boost::GIL bits8* 到 gray8_ptr_t 没有 reinterpret_cast?

尝试按照GIL的设计指南工作,我使用bits__对于我的channel数据类型。我经常将外部数据包装到GILImageView中。然而,即使使用bits__数据指针的类型,我必须添加一个reinterpret_cast才能创建我的ImageView。取以下代码intwidth=3;intheight=2;boost::gil::bits8data8[]={0,1,100,200,50,51};boost::gil::bits8*pBits8=data8;boost::gil::gray8_ptr_tpGray8=pBits8;boost::gil::gray8_view_tv=inte

c++ - 使用 reinterpret_cast 将函数强制转换为 void*,为什么不违法?

这是对我之前的问题Theaddressofafunctionmatchingaboolvsconstvoid*overload的切线跟进.回答者解释说:The[C++11]standarddoesnotdefineanystandardconversionsfroma"pointertofunction"toa"pointertovoid."It'shardtoprovideaquotefortheabsenceofsomething,buttheclosestIcandoisC++114.10/2[conv.ptr]:Aprvalueoftype“pointertocvT,”wher

c++ - 使用 reinterpret_cast 将函数强制转换为 void*,为什么不违法?

这是对我之前的问题Theaddressofafunctionmatchingaboolvsconstvoid*overload的切线跟进.回答者解释说:The[C++11]standarddoesnotdefineanystandardconversionsfroma"pointertofunction"toa"pointertovoid."It'shardtoprovideaquotefortheabsenceofsomething,buttheclosestIcandoisC++114.10/2[conv.ptr]:Aprvalueoftype“pointertocvT,”wher

c++ - reinterpret_cast moSTLy 没用吗?

我已经阅读了关于theuseofreinterpret_cast的各种先前问题。,并且我还阅读了C++标准中的相关措辞。本质上,它归结为指针到指针reinterpret_cast操作的结果不能安全地用于任何东西,除了被转换回原始指针类型。然而,在实践中,reinterpret_cast的大多数实际使用似乎是基于(错误的)假设,即reinterpret_cast与C风格相同throw。例如,我看到很多代码使用reinterpret_cast将char*转换为unsignedchar*以进行字符集转换例行公事。这是完全无害的,但严格来说它不是可移植的-不能保证从char*到unsigned

c++ - reinterpret_cast moSTLy 没用吗?

我已经阅读了关于theuseofreinterpret_cast的各种先前问题。,并且我还阅读了C++标准中的相关措辞。本质上,它归结为指针到指针reinterpret_cast操作的结果不能安全地用于任何东西,除了被转换回原始指针类型。然而,在实践中,reinterpret_cast的大多数实际使用似乎是基于(错误的)假设,即reinterpret_cast与C风格相同throw。例如,我看到很多代码使用reinterpret_cast将char*转换为unsignedchar*以进行字符集转换例行公事。这是完全无害的,但严格来说它不是可移植的-不能保证从char*到unsigned

c++ - 在没有 reinterpret_cast 的情况下将 unsigned char 转换为 std::string 的方法?

我在std::string中有一个我需要的unsignedchar数组,但我目前的方式使用我想避免的reinterpret_cast。有没有更清洁的方法来做到这一点?unsignedcharmy_txt[]={0x52,0x5f,0x73,0x68,0x7e,0x29,0x33,0x74,0x74,0x73,0x72,0x55}unsignedintmy_txt_len=12;std::stringmy_std_string(reinterpret_cast(my_txt),my_txt_len); 最佳答案 使用迭代器构造函数:s

c++ - 在没有 reinterpret_cast 的情况下将 unsigned char 转换为 std::string 的方法?

我在std::string中有一个我需要的unsignedchar数组,但我目前的方式使用我想避免的reinterpret_cast。有没有更清洁的方法来做到这一点?unsignedcharmy_txt[]={0x52,0x5f,0x73,0x68,0x7e,0x29,0x33,0x74,0x74,0x73,0x72,0x55}unsignedintmy_txt_len=12;std::stringmy_std_string(reinterpret_cast(my_txt),my_txt_len); 最佳答案 使用迭代器构造函数:s

C++ union 与 reinterpret_cast

它出现在otherStackOverflowquestions并阅读ISO/IECdraftC++standard的§9.5.1使用union做文字的标准reinterpret_cast的数据是未定义的行为。考虑下面的代码。目标是取0xffff的整数值并将其解释为IEEE754浮点中的一系列位。(Binaryconvertshowsvisuallyhowthisisdone.)#includeusingnamespacestd;unionunionType{intmyInt;floatmyFloat;};intmain(){inti=0xffff;unionTypeu;u.myInt=

C++ union 与 reinterpret_cast

它出现在otherStackOverflowquestions并阅读ISO/IECdraftC++standard的§9.5.1使用union做文字的标准reinterpret_cast的数据是未定义的行为。考虑下面的代码。目标是取0xffff的整数值并将其解释为IEEE754浮点中的一系列位。(Binaryconvertshowsvisuallyhowthisisdone.)#includeusingnamespacestd;unionunionType{intmyInt;floatmyFloat;};intmain(){inti=0xffff;unionTypeu;u.myInt=

c++ - 如何在 C++ 中使用 reinterpret_cast?

我知道C++中的reinterpret_cast可以这样使用:floata=0;intb=*reinterpret_cast(&a);但是为什么不能直接施法呢?floata=0;intb=reinterpret_cast(a);error:invalidcastfromtype'float'totype'int' 最佳答案 全部reinterpret_cast确实是允许您以不同的方式读取您传递的内存。你给它一个内存位置,并要求它读取该内存,就好像它是你要求它读的一样。这就是为什么它只能与指针和引用一起使用。我们以这段代码为例:#in