【发布时间】:2011-09-23 19:09:20
【问题描述】:
我有这个功能
int getrelation(string name, RELATION& output){
bool found=0;
int index=0;
for(int i=0;i<a_attributes.size();i++){
if(name==a_attributes[i].str_name){
found=1;
index=i;
}
}
if(!found){
printf("relation not found");
return 1;
}
output=a_attributes[index];
return 0;
}
RELATION 是一个类 a_attributes 是关系向量。
它应该返回对关系对象的引用。在调用getrelation() 之后,如果我改变了输出的值,那么a_attributes[index] 的值也应该改变,因为这是一个浅拷贝,对吧?
【问题讨论】:
-
我认为您在到达提问位置之前按下了“发布答案”按钮。阅读faq,了解什么是好问题。
-
这里没有问题。问题以问号 (?) 结尾。
-
这里唯一的 C++ 是参考。
标签: c++ reference pass-by-reference deep-copy