作为常量传递的数组与作为常量的数组值有什么区别?
当每个值都是常量时将指针数组传递给函数时:
`void display(Fraction* const ar[], int size);`
一切正常,但是当数组是常数时
`void display(const Fraction* ar[], int size);`
编译器在调用函数时给出以下错误:
`error C2664: 'display' : cannot convert parameter 1 from 'Fraction *[3]' to 'const Fraction *[]'`
主要的:
int main()
{
Fraction* fArray[3];
Fraction* fOne = new Fraction();
Fraction* fTwo = new Fraction();
Fraction* fThree = new Fraction();
fOne->num = 8;
fOne->den = 9;
fTwo->num = 3;
fTwo->den = 2;
fThree->num = 1;
fThree->den = 3;
fArray[0] = fOne;
fArray[1] = fTwo;
fArray[2] = fThree;
display(fArray, 3);
system("pause");
return 0;
}