union of 2 sets; return simple object - C++
<p>What is the best way to implement the following?  I am trying to find the union of 2 sets.  I am creating 2 objects (one called set1 and one called set2).  I aim to create a 3rd object that is a UNION of the two without having to use a copy constructor.  Using dynmanic memory allocation and pointers and/or references is a must. Thanks to anyone to solves this dilemma and any pointers (no pun intended) would help.</p>

<p>Thanks coders.</p>

<p>THE HEADER file</p>

<pre><code>                #ifndef INTEGERSET_H_
                #define INTEGERSET_H_

                class IntegerSet
                {
                private:
                    int * set;
                    int set_size;
                public:
                    IntegerSet(int size);    //default constructor
                    ~IntegerSet();           //destructor
                    IntegerSet * unionOfSets(const IntegerSet &amp; set2);      
                    void insertElement(int k) const;
                    void printSet(int size) const;
                };
                #endif
</code></pre>

<p>THE MAIN file</p>

<pre><code>            #include &lt;iostream&gt;
            #include "integerset.h"

            using std::cout;
            using std::endl;

            int main()
            {
                IntegerSet set1(11);

                //testing below
                set1.insertElement(3);
                set1.insertElement(4);
                set1.insertElement(6);
                set1.insertElement(10);

                set1.printSet(11);
                cout &lt;&lt; endl;

                IntegerSet set2(8);
                set2.insertElement(3);
                set2.insertElement(6);
                set2.insertElement(7);

                set2.printSet(11);
                cout &lt;&lt; endl;



                IntegerSet * obj3 = new IntegerSet(11);
                obj3 =  set1.unionOfSets(set2);                    
                obj3-&gt;printSet(11);

            //  system("pause");
                return 0;
            }
</code></pre>

<p>THE IMPLEMENTATION FILE</p>

<pre><code>            #include "integerset.h"
            #include &lt;iostream&gt;

            IntegerSet::IntegerSet(int size)
            {
                set = new int[size];
                set_size = size;                    
                for (int i = 0; i &lt; size; i++)
                    set[i] = 0;
            }

            IntegerSet::~IntegerSet()
            {
                delete [] set;
            }

            void IntegerSet::insertElement(int k) const
            {
                (*this).set[k] = 1;
            }

            void IntegerSet::printSet(int size) const
            {
                int temp = 0;
                for (int i = 0; i &lt; size; i++)
                {
                    if (set[i] == 1)
                    {
                        std::cout &lt;&lt; i &lt;&lt; " ";
                        temp++;
                    }
                }
                if (temp == 0)
                    std::cout &lt;&lt; "----";
             }


            IntegerSet * IntegerSet::unionOfSets(const IntegerSet &amp; set2) //make this return the union of 2 sets; THIS and the passed ARG reference; return address
            {


                   return this;
            }
</code></pre>
