Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try to avoid C-style casts. If you write (int)ptr where ptr is some pointer this will be a reinterpret_cast which is probably not what you want. For converting numbers to strings and back again check various FAQs. One way to do this is to use the <a href="http://www.cplusplus.com/reference/iostream/stringstream/" rel="nofollow noreferrer">std::stringstream</a> class.</p> <p>A C-style cast is dangerous because it can be used for lots of things and it's not always apparent what it does. C++ offers alternatives (static_cast, dynamic_cast, const_cast, reinterpret_cast) and a functional-style cast which is equivalent to a static cast).</p> <p>In the case of (int)ptr it converts the <em>pointer</em> to an int and <em>not</em> the string representation of a number the pointer points to.</p> <p>You might also want to check out <a href="http://www.boost.org/doc/libs/1_40_0/libs/conversion/lexical_cast.htm" rel="nofollow noreferrer">Boost's lexical_cast</a>.</p> <p>Edit: Don't use typeid for this. You can handle this completely at compile-time:</p> <pre><code>template&lt;typename T&gt; struct doit; // no definition template&lt;&gt; struct doit&lt;int&gt; { static void foo() { // action 1 for ints } }; template&lt;&gt; struct doit&lt;float&gt; { static void foo() { // action 2 for floats } }; .... template&lt;typename T&gt; void blah(T x) { // common stuff doit&lt;T&gt;::foo(); // specific stuff // common stuff } </code></pre> <p>In case T is neither int nor float you get a compile-time error. I hope you get the idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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