Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: hiding some functions
    primarykey
    data
    text
    <p>I redefined some maths functions (so that they're faster -ie: less accurate-, or use templates). I put these functions in a namespace and they work just fine.</p> <p>It happens often, though, that I forget to call functions from my namespace (ie: I forget to write <code>mymath::cos</code> or <code>using mymath::cos;</code> when I want to call <code>cos</code>), and it's pretty tough to find out where I forgot it (until now I found it out only by profiling).</p> <p>Given that</p> <ul> <li>I <strong>only</strong> include standard <code>math.h</code> or <code>cmath</code> headers within my math header, and that</li> <li>I need to include standard math headers (because some of my functions are just wrappers for standard one, and I want them to be inline or they're templated),</li> </ul> <p>is there a portable way to <em>hide</em> standard math function so that a compile error is reported, if global namespace (ie: without a namespace) math functions are used?</p> <p>A solution could be putting an <code>using namespace mymath;</code> at the bottom of my math header file, but this solution doesn't seem that great: it breaks the whole purpose of namespaces; I'd prefer having to explicity say whether to use a function from <code>mymath</code> or from <code>std</code> so that I am forced to choose between a fester or a more accurate function without the risk of forgetting about it.</p> <hr> <p><strong>EDIT</strong>:</p> <p>Many answers say that if I use <code>cos</code> from global namespace (without using <code>std</code> nor <code>mymath</code>), and include <code>cmath</code> (and not <code>math.h</code>), compilation should fail.</p> <p>I don't know what the standard says about it, but:</p> <pre><code>#include &lt;cmath&gt; int main( ) { cos( M_PI ); return 0; } </code></pre> <p>compiles fine with GNU GCC (<code>g++</code>) 4.5.1 (and older versions).</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.
 

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