A* a = new A(x,y);
set<A> aset;
aSet.insert(a);
I did this. Got an error. How shou开发者_开发百科ld I fix it?
Thank you!!!
aset is a set of A, not of pointers to A. So either
set<A*> aset;
or
aset.insert(*a);
but don't think the later makes too much sense.
You're trying to insert a pointer to an A
into your set, but the set is declared as taking A
s directly.
You must either change your set to store pointers:
A* a = new A(x,y);
set<A*> aset;
aSet.insert(a);
or create an instance, rather than a pointer to an instance:
A a = A(x,y);
set<A> aset;
aSet.insert(a);
精彩评论