Using the address of a member variable as an ID
<p>I'm trying to avoid declaring enums or using strings. Although the rationale to do so may seem dubious, the full explanation is irrelevant.</p>

<p>My question is fairly simple. Can I use the address of a member variable as a unique ID?</p>

<p>More specifically, the requirements are:</p>

<ul>
<li>The ID won't have to be serialised.</li>
<li>IDs will be protected members - only to be used internally by the owning object (there is no comparison of IDs even between same class instances).</li>
<li>Subclasses need access to base class IDs and may add their new IDs.</li>
</ul>

<p>So the first solution is this:</p>

<pre><code>class SomeClass
{
    public:
        int mBlacks;

        void AddBlack( int aAge )
        {
            // Can &amp;mBlacks be treated as a unique ID?
            // Will this always work?
            // Is void* the right type?
            void *iId = &amp;mBlacks;

            // Do something with iId and aAge
            // Like push a struct of both to a vector.
        }
};
</code></pre>

<p>While the second solution is this:</p>

<pre><code>class SomeClass
{
    public:
        static int const *GetBlacksId()
        {
            static const int dummy = 0;
            return &amp;dummy;
        }

        void AddBlack( int aAge )
        {
            // Do something with GetBlacksId and aAge
            // Like push a struct of both to a vector.
        }
};
</code></pre>
