Note that there are some explanatory texts on larger screens.

plurals
  1. POOperator overloading and iterator confusion
    text
    copied!<p>I use this code to find the point of a box (<code>g</code>) furthest in the direction <code>d</code> typedef vector_t point_t;</p> <pre><code>std::vector&lt;point_t&gt; corners = g.getAllCorners(); coordinate_type last_val = 0; std::vector&lt;point_t&gt;::const_iterator it = corners.begin(); point_t last_max = *it; do { coordinate_type new_val = dot_product( *it, d ); if( new_val &gt; last_val ) { last_val = new_val; last_max = *it; } } while( it != corners.end() ); return last_max; </code></pre> <p>I also have a template operator overload for the operator <code>!=</code> for the class <code>vector_t</code> which is in the namespace <code>point</code>.</p> <pre><code>namespace point { template &lt; typename lhs_vector3d_impl, typename rhs_vector3d_impl &gt; bool operator!=( const typename lhs_vector3d_impl&amp; lhs, const typename rhs_vector3d_impl&amp; rhs ) { return binary_operator_not_equal&lt;lhs_vector3d_impl, rhs_vector3d_impl&gt;::apply( lhs, rhs ); } }; </code></pre> <p>The overload works fine in most cases but when I use with iterators (i.e. <code>it != corners.end()</code>) it breaks down since I did not intend this function in that case. I can tell it's because of the template parameters resolution going wrong but i don't know why:</p> <pre><code>lhs_vector3d_impl=std::_Vector_const_iterator&lt;std::_Vector_val&lt;std::_Simple_types&lt;legend::geometry::point::Carray_Vector3d&lt;int32_t&gt;&gt;&gt;&gt;, rhs_vector3d_impl=std::_Vector_iterator&lt;std::_Vector_val&lt;std::_Simple_types&lt;legend::geometry::point::Carray_Vector3d&lt;int32_t&gt;&gt;&gt;&gt; </code></pre> <p>I understand the wrong functions get called but I don’t understand why…</p> <p>So basically my question is how comme iterator comparaison gets resolved with my function instead of an operator in the std namespace and how can I prevent this function from being used.</p> <p>Note 1: I am beginning with template so I may be doing something very wrong without knowing, if so please kindly tell.</p> <p>Note 2: this code is used mainly for academic purposes so I really want to do most of it by hand.</p> <p>Note 3: using Visual Studio 2012 C++ compiler</p>
 

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