如何迭代作为指针传递的对数组参数
how do i iterate the pair array arguments passed as a pointer?
如何迭代作为指针传递的对数组参数?
我曾经试着用作为参考对&arr。但它也不起作用。我可以通过pair<lli,lli> a[n];
作为参考吗??
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
typedef long long int lli;
typedef unsigned long long int ulli;
void yeah( pair<lli,lli> *arr ){
// cout << arr[0].ff; 100
//this doesnt work :(
for(auto e : arr){
cout << e.ff << " " << e.ss << endl;
}
}
int main() {
int n = 10;
pair<lli,lli> a[n];
a[0].ff = 100;
a[1].ss = 150;
yeah(a);
}
这是我获取的错误
prog.cpp:在函数"void yes(std::pair("中:prog.cpp:13:18:错误:调用"begin(std::pair&("没有匹配的函数for(auto e:arr({^^
固定大小数组的可能解决方案:
template<std::size_t size>
void foo(std::pair<int, int> (&arr)[size]) {
for (auto e : arr) {
...
}
}
constexpr std::size_t n = 10; // should be known at compile time
std::pair<int, int> a[n];
foo(a);
我建议放弃VLA(它无论如何都不是C++的一部分(,改用std::vector
。包括<vector>
并将声明更改为:
std::vector<std::pair<lli, lli>> a(n);
函数的签名为:
void yeah(std::vector<std::pair<lli, lli>> &arr)
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 估计函数参数数组的维度
- 温度参数数组的内存泄漏
- 如何将值附加到命令行参数数组?
- libpqxx:如何绑定参数数组
- 如何在德尔福中C++参数数组指针算术
- C++函数参数或参数数组
- 将 std::function 代理为需要参数数组的 C 函数
- 分析字符串参数数组
- Pro*C传递参数数组
- OpenCV错误:cvGetSize中的错误参数(数组应该是CvMat或IplImage)
- c++无限参数数组
- 查找命令行参数数组中的元素数
- 如何将目录中所有具有完整路径的文件传递到execv中的参数数组
- ODBC:参数数组-忽略参数
- 使用lambda参数数组