函数调用的问题?
#include "iostream.h"
void putValues(const int *);
int main()
{
int arr[3]={1,2,3};
putValues(arr);
return 0;
}
void putValues(const int* a)
{
for(int i=0;i<3;i++)
cout<<a[i]<<endl;
}
调用函数putValues(const int* a)时,根据函数声明,实参应该是一个指向整型常量的指针,但是此程序中实参是一个数组名,数组名是一个指针常量,那么这样的调用应该报错啊,怎么程序运行正常呢?
如果把函数参数作一下修改,形参为int* const a
#include "iostream.h"
void putValues(int const *);
int main()
{
int arr[3]={1,2,3};
putValues(arr);
return 0;
}
void putValues(int* const a)
{
for(int i=0;i<3;i++)
cout<<a[i]<<endl;
}
出现错误,unresolved external symbol "void __cdecl putValues(int const *)" (?putValues@@YAXPBH@Z)
在const修饰符的使用上还有许多不明白的地方,还希望大家不吝赐教!