Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is explained in the book "C++ Templates - The Complete Guide". It's because your operator[] takes size_t, but you pass a different type which first has to undergo an implicit conversion to size_t. On the other side, the conversion operator can be chosen too, and then the returned pointer can be subscript. So there is the ambiguity. Solution is to drop the conversion operator. They should generally be avoided as they just introduce problems, as you see.</p> <p>Provide a <code>begin</code> and <code>end</code> member function that returns <code>vector</code> and <code>vector + 4</code> respectively. Then you can use <code>v.begin()</code> if you want to pass to native openGL functions.</p> <p>There is a bit confusion in the comments. I think i will update this answer now to reflect the most recent concept of this.</p> <pre><code>struct Vector4 { // some of container requirements typedef GLfloat value_type; typedef GLfloat&amp; reference; typedef GLfloat const&amp; const_reference; typedef GLfloat * iterator; typedef GLfloat const * const_iterator; typedef std::ptrdiff_t difference_type; typedef std::size_t size_type; static const size_type static_size = 4; // returns iterators to the begin and end iterator begin() { return vector; } iterator end() { return vector + size(); } const_iterator begin() const { return vector; } const_iterator end() const { return vector + size(); } size_type size() const { return static_size; } size_type max_size() const { return static_size; } void swap(Vector4 &amp; that) { std::swap(*this, that); } // some of sequences reference operator[](size_type t) { return vector[t]; } const_reference operator[](size_type t) const { return vector[t]; } // specific for us. returns a pointer to the begin of our buffer. // compatible with std::vector, std::array and std::string of c++1x value_type * data() { return vector; } value_type const* data() const { return vector; } // comparison stuff for containers friend bool operator==(Vector4 const&amp;a, Vector4 const&amp;b) { return std::equal(a.begin(), a.end(), b.begin()); } friend bool operator!=(Vector4 const&amp;a, Vector4 const&amp;b) { return !(a == b); } friend bool operator&lt;(Vector4 const&amp;a, Vector4 const&amp;b) { return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()); } friend bool operator&gt; (Vector4 const&amp;a, Vector4 const&amp;b) { return b &lt; a; } friend bool operator&lt;=(Vector4 const&amp;a, Vector4 const&amp;b) { return !(b &lt; a); } friend bool operator&gt;=(Vector4 const&amp;a, Vector4 const&amp;b) { return !(a &lt; b); } private: GLfloat vector[4]; } </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