std::set problems

Why doesn't this code work:


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
#include <iostream>
#include <set>

class myc {
public:
    int a, b;
    myc(int aa, int bb) {a = aa; b = bb;}
    myc operator = (const myc & q) {
        if (this != &q) { a = q.a; b = q.b; }
        return *this;
    }
};

bool operator <(myc &a, myc &b) { return a.a < b.a; }

bool operator  == (myc &a, myc &b) { return a.a == b.a; }

int main(int argc, const char * argv[])
{
    
    set<myc> ms;

    myc *q1 = new myc(8,9);
    myc *q2 = new myc(99,10);
    myc *q3 = new myc(-6,1);
    myc *q4 = new myc(0,0);    
        
    ms.insert(*q1);
    ms.insert(*q2);
    ms.insert(*q3);
    ms.insert(*q4);
}


:(
Last edited on
What do you mean by "doesn't work"? How do you know it doesn't work?
doesn't compile.
What errors are you getting and on what line.

It's much easier for us to solve the problem when we know what the problem is. Be specific.
It seems that set has to be declared to something before using it in main.
Topic archived. No new replies allowed.