C++ C++;错误 ;1传递数组指针时发生错误C2664

C++ C++;错误 ;1传递数组指针时发生错误C2664,c++,C++,我不明白如何解决这个问题,尝试了很多方法,但没有解决方案。如果您能帮忙,我们将不胜感激。谢谢 错误1错误C2664:'void showallbuss(const Bus*[],int):无法将参数1从'Bus**转换为'const Bus*[]' void showallbus(const Bus*pbuse[],int numBus){ for(int i=0;i

我不明白如何解决这个问题,尝试了很多方法,但没有解决方案。如果您能帮忙,我们将不胜感激。谢谢

错误1错误C2664:
'void showallbuss(const Bus*[],int)
:无法将参数1从
'Bus**
转换为
'const Bus*[]'

void showallbus(const Bus*pbuse[],int numBus){
for(int i=0;icout对于任何类型的
T
T*
都可以隐式转换为
const T*
,但是
T**
不能隐式转换为
const T**
。允许这样做可能会违反常量(1)

但是,
T**
可以转换为
const T*const*
。由于函数不会以任何方式修改数组,因此只需按如下方式更改其参数:

void showAllBuses(const Bus* const * pBuses, int numBus) {
请记住,在函数参数声明中,
*
和最外层的
[]
是同义词


(1) 代码如下:

const int C = 42;
int I = -42;
int *p = &I;
int *pp = &p;
const int **cp = pp;  // error here, but if it was allowed:
*cp = &C;  // no problem, *cp is `const int *`, but it's also `p`!
*p = 0;  // p is &C!

谢谢!已修复并理解:)
const int C = 42;
int I = -42;
int *p = &I;
int *pp = &p;
const int **cp = pp;  // error here, but if it was allowed:
*cp = &C;  // no problem, *cp is `const int *`, but it's also `p`!
*p = 0;  // p is &C!