Accessing a static member that has the same name as an inner type
<p>I have a few classes that define sequences whose values must be available both at compile-time through a <code>value</code> member and at runtime as an actual instance of the type. So my base types for an arithmetic sequence looks a little like this,</p>

<pre><code>template&lt;int A, int D&gt;
struct ArithmeticSequence : public Sequence {
    ArithmeticSequence(VALUE v)
        : Sequence(v) {}

    template&lt;unsigned int N&gt;
    struct VALUE_N : public VALUE {
        static const int value = A+(D*N);
        operator int() { return value; }
    };
};
</code></pre>

<p><code>class Sequence</code> currently just defines an inner class <code>VALUE</code> (currently empty) and a constructor that takes a <code>VALUE</code>, but I will move the <code>operator int()</code> of <code>VALUE_N</code> into <code>VALUE</code> and <code>Sequence</code> will define iterators, etc, further down the line.</p>

<p>Now, classes should extend from <code>ArithmeticSequence</code> and define constants for each of the members of the sequence. I've got two methods that I think will work for this, if I don't mind instances of sequences being able to be constructed from members of related sequences (that is, sequences with the same initial value and common difference), I can use <code>typedef</code>:</p>

<pre><code>struct mySequence : public ArithmeticSequence&lt;0,1&gt; {
    mySequence(VALUE val = VALUE_N&lt;0&gt;::value)
        : ArithmeticSequence(val) {}

    typedef VALUE_N&lt;0&gt; zeroth;
    typedef VALUE_N&lt;1&gt; first;
    // ...
};
</code></pre>

<p>And if I do, I can extend from <code>VALUE_N</code>:</p>

<pre><code>struct mySequence : public ArithmeticSequence&lt;0,1&gt; {
    mySequence(VALUE val = VALUE_N&lt;0&gt;::value)
        : ArithmeticSequence(val) {}

    struct zeroth : public VALUE_N&lt;0&gt; {};
    struct first  : public VALUE_N&lt;1&gt; {};
    // ...
};
</code></pre>

<p>In both these cases I think I can use <code>mySequence::zeroth::value</code> to get at the value at compile time, and <code>mySequence::zeroth()</code> to get a runtime object. However using the second method causes the compiler confusion as to whether I'm declaring a function or initializing an instance, so I need, <code>mySequence s1 ((mySequence::zeroth()));</code> instead of <code>mySequence s1 (mySequence::zeroth())</code>.</p>

<p>Now, I've found that the following is valid,</p>

<pre><code>struct mySequence : public ArithmeticSequence&lt;0,1&gt; {
    mySequence(VALUE val = VALUE_N&lt;0&gt;::value)
        : ArithmeticSequence(val) {}

    struct zeroth : public VALUE_N&lt;0&gt; {};
    static const zeroth zeroth;
    struct first  : public VALUE_N&lt;1&gt; {};
    static const first first;
    // ...
};
</code></pre>

<p>But my question (finally) is, what are the rules as to which one I'm accessing at any time? I can use <code>static const int i = mySequence::zeroth::value</code> and, <code>mySequence s1 (mySequence::zeroth)</code>, so the right thing seems to happen there, but if I say <code>mySequence::zeroth z</code> instead of treating <code>zeroth</code> as a class it treats it as the variable. This isn't a problem in this case since I don't want people creating new <code>mySequence::zeroth</code>'s or any other value, but I think if I don't understand when it will use each one I may let myself in for trouble at a later date.</p>

<p>Sorry about the extra long post, and thankyou in advance for your time and patience for anyone who got this far. I'm wondering now if I should have put in all the back story or just simply asked the question, if the concensus is I should have, I'll edit it down. Thanks.</p>

<p><strong>Edit</strong>. Please note, as I have written it above, using the struct method as opposed to the typedef does <em>not</em> provide any protection against using another "related" sequences members to construct a sequence object, it is needed, I think, however for the last example to work.</p>
