c++如何将两个数组传递给函数并同时返回它们
c++ how to pass two arrays to a function and return them both?
我有两个数组:
int sudoku[9][9];
bool possiblevalues[81][9];
我想初始化它们。我将它们传递给函数initialize (sudoku, possiblevalues)。这个函数初始化数组并返回它们。现在我的问题是:我怎样才能正确地退货?因为它不允许我使用指针或引用。
通过引用获取数组,那么您不需要返回它们:
void initialize(int (&sudoku)[9][9], bool (&possiblevalues)[81][9])
{
// code to initialize here.
// Any changes you make here will be reflected to the arrays
// that have been passed to the function
}
像这样使用原始数组并不是特别"好"的c++。我建议你学习如何使用std::vector
或std::array
相关文章:
- 从函数返回const char*数组
- 检查函数返回类型是否与STL容器类型值相同
- 从 c 或 cpp 系列子函数返回到主函数
- 从函数返回任意简单类型的数据
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 从 C++ 中的函数返回数组地址问题
- VirtDisk.h QueryChangesVirtualDisk() 函数返回 RangeCount 为 0
- 为什么glGetSubroutineIndex为不同的函数返回相同的值?
- 在 c++ 中将函数返回类型指定为模板参数
- 从封装在对象中的函数 C++ 返回时为空的列表
- 为什么向量内部的指针在从函数返回时会发生变化?
- 函数返回的 rvalue 引用(表达式)是 xvalue - 但没有标识?
- 程序中的布尔函数返回输入的范围无论如何都是无效的
- 寿命延长从函数返回引用
- 程序不向函数返回值
- 字符串函数返回奇怪的值
- 类的大问题,以及从空函数c++返回
- 为什么在尝试测量函数返回所需的时间时,我的运行时编号是错误的?
- C++二叉搜索树模板从函数返回节点
- NVCC 错误:string_view.h:constexpr 函数返回是非常量