- 论坛徽章:
- 0
|
void my::addItems(const vector<Item> &tis){
ChildItem * ppti = NULL;
for(vector<Item>::iterator it = tis.begin();it != tis.end();it ++){
ppti = static_cast<ChildItem *>(it);
..........
}
在遍历时,编译器说:
An object or reference of type "std::vector<Item,std::allocator<Item> >::iterator" cannot be initialized with an rvalue of type "std::_Ptrit<Item,long,
const Item *,const Item &,Item *,TItem &>"
好像是说引用不能像我那样遍历。那若我希望遍历要怎么做?
还有那个static_cast,因为ChildItem是Item的子类,本来我是想用dynamic_cast更好些,但因为Item只是个简单类,没有虚函数,所以不让用dynamic_cast,这种情况下是不是只有static_cast这一条路可走? |
|