views:

32

answers:

2

I have the following code:

class asd {  
    public:  
    int b;  
    asd() { b = rand() % 10; }  
    bool operator<(asd &other) { return b < other.b; }  
};

int main() {  
    asd * c; c = new asd();  
    set <asd> uaua;  
    uaua.insert(c);  
}

Yet when running it, I get this error:

main.cpp|36|error: no matching function for call to ‘std::set<asd, std::less<asd>, std::allocator<asd> >::insert(asd*&)’|

I'm using g++ 4.4.3

Could someone please tell me where I'm going wrong? I've tried to crack this for a good while, but can't seem to find the solution. Thanks

+3  A: 

You have a set of asd, and you're trying to add a pointer.

Use:

asd c; 
set <asd> uaua;
uaua.insert(c);
Matthew Flaschen
Ahhh, I feel so stupid. Thank you.
tsiki
+1, you can also use construction in place: `set<asd> uaua; uaua.insert( asd() );`
David Rodríguez - dribeas
A: 

Try declaring set<asd*> instead of just set<asd>.

bmargulies