void test(vector a)
{
a.push_back(0);
}
void test2()
{
vector temp;
test(temp);
int temp_size = temp.size();
}
请问为什么temp_size 还是0呢,我调用void test(vector a)函数传进去了vector temp,放入一个数据
关于#c++#的问题:}请问为什么temp_size 还是0呢,我调用void test(vector a)函数传进去了vector temp
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
冷0_O 2022-09-15 11:55关注改成引用传递才行,而且你这个也有语法错误,vector变量声明你没指定类型。
#include <iostream> #include <vector> void test(std::vector<int> &a) { a.push_back(0); } void test2() { std::vector<int> temp; test(temp); int temp_size = temp.size(); std::cout << "temp_size = " << temp_size << std::endl; } int main() { test2(); return 0; }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报