Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are accessing the value_type trough the variable instance and not the variable type.</p> <p><strong>Method 1</strong> - this works:</p> <pre><code>typedef std::vector&lt;Vector&gt; MyVector; MyVector v; unsigned u = MyVector::value_type::Dim(); </code></pre> <p><strong>Method 2</strong> - or this:</p> <pre><code>std::vector&lt;Vector&gt; v; unsigned u = std::vector&lt;Vector&gt;::value_type::Dim(); </code></pre> <p>If you typedef like on method 1 you do not hardcode assumptions on vector template parameter and you write clean code.</p> <hr> <p><strong>Edit:</strong> Expanded to explain the behavior for this issue as requested by question owner:</p> <p>The scope resolution operator <code>::</code> has higher <a href="http://www.cppreference.com/wiki/operator_precedence" rel="nofollow noreferrer">precedence</a> than any other C++ operator. This includes the Member access from an object <code>.</code> operator. Thus when you write something like:</p> <pre><code>unsigned u= v.value_type::Dim(); </code></pre> <p>this resolves to the following C++ code:</p> <pre><code>unsigned u = v.SVector&lt;double, 2&gt;::Dim(); </code></pre> <p>and ultimately what is resolved first is the <code>SVector&lt;double, 2&gt;::Dim()</code> part. This would force the vector instance declared trough variable <code>v</code> to have a templatized inner class named SVector. And because this does not happen this results in error:</p> <pre><code>error C2039: 'SVector&lt;double,2&gt;' : is not a member of 'std::vector&lt;_Ty&gt;' </code></pre> <p>STL <code>vector</code> would have to be "expanded" for each usage of this pattern (accessing value_type trough variable instance and not variable type). This is not a good solution as it leads to lots of boilerplate and <strong>unnecessary and unmaintainable code</strong>. By following the above mentioned solutions you avoid all this and can easily do what you wanted.</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