您创建了一个Buyer对象,但从未将其添加到向量中。如果你确实这么做了,我希望你做的是这样的: int main(){ 买家b; buyer_queue.push_back(b); b.start(); } 以上在向量中找不到买方,因为''b''不是* 向量,它在主函数中。如果你这样做: int main(){ 买方b; buyer_queue.push_back(b); buyer_queue [0] .start(); } 然后你将在一个* in *的对象上调用start向量。You created a Buyer object, but never added it to the vector. If youdid, I expect you did something like this:int main() {Buyer b;buyer_queue.push_back(b);b.start();}The above will not find the Buyer in the vector because ''b'' isn''t *in*the vector, it''s in the main function. If you do this:int main() {Buyer b;buyer_queue.push_back(b);buyer_queue[0].start();}then you will be calling start on an object that is *in* the vector. 我想你已经删除了*远*太多了。你不要把b推到矢量 的任何地方,所以它不在矢量中。即使你这样做了,为什么要立即 搜索并删除它?发布的简化很好,但不是代码含义的代价。 您确定要将对象本身存储在向量?你知道,当你调用push_back时,一个向量会生成对象的*副本*,因此向量中的对象的 地址将永远不会相同作为原始的 对象。如果你需要使用地址来比较对象,那么你需要推送指针,而不是对象。 (在这种情况下,只需将它与 指针进行比较,而不是& *它。) -HowardI think you''ve removed *far* too much. You don''t push b onto the vectoranywhere, so it''s not in the vector. And even if you did, why immediatelysearch for it and remove it? Simplification for posting is fine, but not atthe expense of the meaning of the code.Are you sure you want to store the objects themselves in the vector? Youknow, a vector makes a *copy* of the object when you call push_back, so theaddress of the object in the vector wil *never* be the same as the originalobject. If you need to use addresses to compare objects, then you need topush pointers, not objects. (And in that case, just compare *it with thepointer, instead of &*it.)-Howard 这篇关于矢量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!