【发布时间】:2015-10-05 21:09:53
【问题描述】:
假设您有一个迭代器指向列表中的一个对象,并且您想编写一个函数,将迭代器指向的任何对象复制到另一个指定的列表中。这可能吗?
例如
std::list<Customer> customer;
for (customer=customers.begin(); customer!=customers.end(); ++customer){
std::list<Inventory>::iterator tool;
for (tool=inventory.begin(); tool!=inventory.end(); ++tool){
tool->addToWaitlist( customer );
}
}
在哪里
void addToWaitlist(std::list<Customer>::iterator customer){
std::list<Customer>::iterator person;
if (!wait_list.empty()){
for (person=wait_list.begin(); person!=wait_list.end(); ++person){
// Add customer with respect to time stamp
//if ( customer.getTime() <= person->getTime() ){
// wait_list.insert( person, customer );
}
}
} else {
// Add first person to wait list
wait_list.push_back( customer );
}
}
【问题讨论】:
-
是的。请出示您的代码。
-
“这可能吗?” 是的,有可能。你这样做有没有遇到什么特别的问题?请逐字显示相关的问题代码和所有错误消息。