c++ member variable not being changed outside of function
<p>The attached code seems to work as desired, but when it is in separate files main.cpp, Set.h, Set.cpp filled is not decrementing outside of the remove function. I really don't understand what is going on here. Or why it would make any difference that its all in one file.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
typedef int value_type;

class Set {
private:
value_type *dataArray, size, filled;
public:

Set() {
    size = 50;
    dataArray = new value_type[size];
    filled = 0;
}

bool Set::isFull() const {
    return (filled == size) ? true : false; // if filled is equal to size then full.
}

bool Set::remove(const value_type&amp; item) {

    for (int index = 0; index &lt; filled; index++) {
        if (index != (filled - 1) &amp;&amp; dataArray[index] == item) {
            dataArray[index] = dataArray[filled - 1];
            --filled;
            return true;

        } else {
            --filled;
            return true;
        }
    }

    return false;
}

void Set::insert(const value_type&amp; newItem) {

    if (!isFull()) {
        dataArray[filled] = newItem;

        filled++; // increment filled to account for new entry.

    }
}

friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const Set&amp; obj) {
    out &lt;&lt; "\nfilled: " &lt;&lt; obj.filled &lt;&lt; endl;
    out &lt;&lt; "{";

    for (int index = 0; index &lt; obj.filled; index++) {
        out &lt;&lt; obj.dataArray[index];
        if (index != (obj.filled - 1))
            cout &lt;&lt; ",";

    }
    out &lt;&lt; "}";
    return out;
}
};
Set firstSet;

void pauseNwait() {
cout &lt;&lt; "&lt;--Enter to Continue--&gt;";
cin.ignore();
cin.get();
}

int main() {

int choice = -1;
value_type input;

while (choice != 0) {
    cout &lt;&lt; "       Set Manager" &lt;&lt; endl
            &lt;&lt; " (1) Add item to Set 1" &lt;&lt; endl
            &lt;&lt; " (2) Remove item from Set 1" &lt;&lt; endl
            &lt;&lt; " (0) Exit" &lt;&lt; endl
            &lt;&lt; "-----------------------------------------" &lt;&lt; endl
            &lt;&lt; "Choose: ";
    cin.clear();

    if (cin &gt;&gt; choice) {
        switch (choice) {
            case 0:
                // Exit.
                break;
            case 1:
                cout &lt;&lt; "Enter int to add to list: ";
                cin &gt;&gt; input;
                firstSet.insert(input);
                cout &lt;&lt; "First Set: " &lt;&lt; firstSet &lt;&lt; endl;
                pauseNwait();
                break;
            case 2:
                cout &lt;&lt; firstSet &lt;&lt; endl;
                cout &lt;&lt; "Enter item to remove from list: ";
                cin &gt;&gt; input;
                firstSet.remove(input);
                cout &lt;&lt; "First Set: " &lt;&lt; firstSet &lt;&lt; endl;
                pauseNwait();
                break;
            default:
                break;
        }
    } else {
        cin.clear(); // clear cin to avoid invalid menu input errors.
        cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');
    }
}
return 0;
}
</code></pre>
