首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请问一下:怎样修改vector中的对象

2012-02-09 
请教一下:怎样修改vector中的对象?在vector中放一个对象我想修改对象中的一个成员变量或者用它的参数构造

请教一下:怎样修改vector中的对象?
在vector中放一个对象   我想修改对象中的一个成员变量  
或者用它的参数构造一个新的对象   在vector中把它替换掉也行  
下面是一部分源码(……这样写自然不对……)
container是一个vector的容器
我想修改其中一个元素(对象)的成员变量(*y)-> vertexcount1

    for(Iter   y   =   container.begin();y   !=   container.end();y++){
if(((*y)-> vertex1   ==   tempvertex1   ||   (*y)-> vertex1   ==   tempvertex2)   &&   (*y)-> vertexcount1   ==1){
(*y)-> vertexcount1++;
}else   if(((*y)-> vertex2   ==   tempvertex1   ||   (*y)-> vertex2   ==   tempvertex2)&&   (*y)-> vertexcount2   ==1){
(*y)-> vertexcount2++;
}
}

[解决办法]
(*y)-> vertexcount1
==>
(*y).vertexcount1 或者是 y-> vertexcount1

如果你的 vector 中的对象可以这么被直接访问成员,
那么这样是可以的。
否则使用成员函数访问即可:y-> memberFunc();

热点排行