我正在学习 c++ 并尝试一些事情。编译器不会在注释 2 行抛出错误。
int main(){
vector<double> a1;
a1.push_back(3);
a1.push_back(7);
a1.push_back(2);
vector<double>& a2 = a1; //COMMENT 1: This line has no error
vector<double>& a4 = print(a2); //COMMENT 2: Why this line has error? R value is an object then it should be referenced by a4?
return 0;
}
vector<double> print(vector<double>& a3){
cout<<"In print function the size of vector is :";
cout<<a3.size()<<endl;
return a3;
}