An object field returns the object itself, not an instance stored in the field
<p>(Not sure if this title is the best description...)</p>

<p>Hi all. I need a help with the following code. In <code>process</code> function, I want <code>cc</code> and <code>cc_sub</code> (which is obtained as a field in <code>cc</code>) to show different contents (as they are originally made so) but they show the same. <code>Storage</code> instances are made in <code>makeObj</code> function. Could someone tell me what's wrong and how to work this around? Thank you.</p>

<pre><code>Int process(const Storage cc) {
    Storage cc_sub = (Storage&amp;) cc.data;  // Here
    cout &lt;&lt; ... &lt;&lt; endl;         // Contents from cc and cc_sub are the same though they are not supposed to be.
}

class Storage {
    public:
        Storage() {
            this-&gt;data = NULL;
        }
        Storage(const Storage&amp; obj) { //Copy Constructor. Result is the same even if I removed this entire clause.
            this-&gt;data = obj.data;
        }
        void* data;
        void setData(Storage dPtr) {
            this-&gt;data = &amp;dPtr;
        }
};

Storage makeObj(std::string* s) { // I want to keep the return value as value instead of pointer, 
                       // since when it returns pointer the values pointed by reference behaved unexpectedly (guess it's because of temporary object type of error)... 
    Storage cc;
    :
    cc.setData(makeObj(&amp;subString)); 
    return cc;
    :
}
</code></pre>
