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; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 smptlib使用465端口发送邮件失败
- ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
- ¥15 对于squad数据集的基于bert模型的微调
- ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
- ¥20 steam下载游戏占用内存
- ¥15 CST保存项目时失败
- ¥15 树莓派5怎么用camera module 3啊
- ¥20 java在应用程序里获取不到扬声器设备
- ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
- ¥15 Attention is all you need 的代码运行