【发布时间】:2021-08-04 13:07:25
【问题描述】:
我一直在尝试在 C++ 中创建一个函数,它接受一个列表,对其执行一些操作,然后返回它。但该函数不接受 std::list 作为有效的返回类型或参数类型。
#include <iostream>
#include <list>
std::list list_function(int n, std::list progress) {
}
int main() {
/* std::list<int> test_list = {1, 2, 3, 4, 4854};
test_list.push_back(10); // some unrelated testing
for (int x : test_list) {
std::cout << x << '\n';
} */
}
我在网上找不到任何答案,我该怎么办?
【问题讨论】:
-
顺便说一句,最好默认为
std::vector容器而不是std::list。