Class and this, set manipulation

Hello, I have been working on a project that manipulates sets (unique elements within an array), and I am having issues with how to go about calling the two sets in the functions of union and intersection. These program fragments are from my main and class implementation files and do compile, but once the program terminates I get a pause then a "RUN FAILED". Any suggestions or tips on what I need to change?

For this code I feel that I am assigning setThree inappropriately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Main
  cout << "The union of the first and second set: " << endl;
    setThree = setThree.setUnion(setOne, setTwo);
    setThree.print();
    
    cout << "The common items within these two sets are: " << endl;
    setThree = setThree.setIntersection(setOne, setTwo);
    setThree.print();

//Class implemenetation
unorderedSetType unorderedSetType::setUnion(unorderedSetType first, unorderedSetType second)
{
    for (int i=0; second.length > i; i++)
    {
        if (first.seqSearch(second.list[i]) == -1)
            first.insertEnd(second.list[i]);
    }
    return first;
}

unorderedSetType unorderedSetType::setIntersection(unorderedSetType first, unorderedSetType second)
{
    unorderedSetType third(100);
    for (int i=0; first.length > i; i++)
    {
        
        if (second.seqSearch(first.list[i]) != -1)
            third.insertEnd(first.list[i]);
                
    }
    return third;
}



Another separate issue: I am new to "this" pointer and have been experimenting with it. My setUnion function has "this" manipulate setOne when I want it to "temporarily manipulate for this function only." (I'm sure there's a term for that)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//Main
  cout << "The union of the first and second set: " << endl;
    setThree = setOne.setUnion(setTwo);
    setThree.print();
    
    cout << "The common items within these two sets are: " << endl;
    setThree = setOne.setIntersection(setTwo);
    setThree.print();

//Implementation file
unorderedSetType unorderedSetType::setUnion(unorderedSetType second)
{
    for (int i=0; second.length > i; i++)
    {
        if (this->seqSearch(second.list[i]) == -1)
            this->insertEnd(second.list[i]);
    }
    return *this;
}

unorderedSetType unorderedSetType::setIntersection(unorderedSetType second)
{
    unorderedSetType third(100);
    for (int i=0; this->length > i; i++)
    {
        if (second.seqSearch(this->list[i]) != -1)
            third.insertEnd(this->list[i]);
    }
    return third;
}


Any help is appreciated. Thank you for your time!
After much trial and error I found that I could do
1
2
3
4
5
6
7
8
9
10
11
unorderedSetType unorderedSetType::setUnion(unorderedSetType second)
{
    unorderedSetType temp(*this);
    
    for (int i=0; second.length > i; i++)
    {
        if (temp.seqSearch(second.list[i]) == -1)
            temp.insertEnd(second.list[i]);
    }
    return temp;
}

This resolved my second part of the question, but it still gives me the run failed error.
Topic archived. No new replies allowed.