不同大小的向量数组的大小 cpp
Size of array of vectors of different sizes cpp
我有一个接受不同大小的向量数组的函数,我想知道数组中存在多少个向量
int dfs(vector<int> g[])
{
int n=?;//(no. of vector in array)
}
在C++中没有办法做到这一点:函数参数中的数组类型衰减到没有大小信息的指针。
最好的选择是将参数作为std::vector<std::vector<int>>
,但您在评论中提到这是不可能的。
如果您确定将传递数组(与指向数组的指针相比(,另一种选择是将定义更改为如下所示的内容:
template <std::size_t n>
int dfs(std::vector<int>(&g)[n]) {
// n is the number of elements in the array
}
相关文章:
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 不同大小的向量数组的大小 cpp
- 如何循环访问 cpp 中的函数返回的字符指针数组
- 为什么我的 cpp 数组大小是 4 的倍数?
- 如何在 llvm 的 cpp api 中使用 CreateInBoundsGEP 来访问数组的元素?
- 如何使用 PHP-CPP 在 PHP 类中添加静态数组
- cpp 数组 - 分配常量索引有效,而非常量索引不起作用
- 将特定索引处的字符数组内容与字符文字 - cpp 进行比较
- 为什么当我在 CPP 的初始化中指定多维数组时,它必须有边界
- 通过矢量下标访问 Fortran 数组,相当于 cpp
- 如何在 CPP 中将 Typedef basic_string字符串转换为<char>字节数组
- 在 GRPC 中使用字节数组 (cpp)
- 如何使用 cpp 消除 2d 数组中的边框元素
- cpp 初始值设定项太多 - 数组中的结构中的结构
- 2D 数组在 CPP 中查找行的总和
- 具有不同构造函数参数的 CPP 对象数组
- CPP 中结构类型的指针的矢量数组
- 终端命令输出到 CPP 中的数组
- 不能打印cpp数组中的第一个元素