开发者

C++ question. about container and instance of class

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 As 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); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜