更新时间:2022-04-07 00:19:08
自从你的函数声明:
void printMatrix(vector< vector<int> > *matrix)
指定一个指针,它本质上是通过引用传递的.但是,在 C++ 中,***避免使用指针并直接传递引用:
specifies a pointer, it is essentially passed by reference. However, in C++, it's better to avoid pointers and pass a reference directly:
void printMatrix(vector< vector<int> > &matrix)
和
printMatrix(matrix1); // Function call
这看起来像一个普通的函数调用,但它是通过引用传递的,如函数声明中所示.这可以避免不必要的指针取消引用.
This looks like a normal function call, but it is passed by reference as indicated in the function declaration. This saves you from unnecessary pointer dereferences.