Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>reinterpret_casts</code> are used for low-level implementation defined casts. According to the standard, <code>reinterpret_casts</code> can be used for the following conversions (C++03 5.2.10):</p> <ul> <li>Pointer to an integral type</li> <li>Integral type to Pointer</li> <li>A pointer to a function can be converted to a pointer to a function of a different type</li> <li>A pointer to an object can be converted to a pointer to an object of different type</li> <li>Pointer to member functions or pointer to data members can be converted to functions or objects of a different type. The result of such a pointer conversion is unspecified, except the pointer a converted back to its original type.</li> <li>An expression of type A can be converted to a reference to type B if a pointer to type A can be explicitly converted to type B using a <code>reinterpret_cast</code>.</li> </ul> <p>That said, using the <code>reinterpret_cast</code> is not a good solution in your case, since casting to different types are unspecified by the standard, though casting from <code>char *</code> to <code>unsigned char *</code> and back should work on most machines.</p> <p>In your case I would think about using a <code>static_cast</code> or not casting at all by defining <code>stg</code> as type <code>char *</code>:</p> <pre><code>template&lt;class ITER_T&gt; char *copy_binary( unsigned char length, const ITER_T&amp; begin) { // alloc_storage() returns a char* char* stg = alloc_storage(length); std::copy(begin, begin + length, stg); return stg; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload