N简单,什么是CONST修饰的指针不可以赋给不用CONST修饰的指针呢?有代码。。。谢谢。。。(菜鸟没有分了)
#include <iostream>
using namespace std;
const int ArSize = 8;
int sum_Arr(const int* begin,const int *end);
int main()
{
int Ar[ArSize]={1,2,4,8,16,32,64,128};
int sum=sum_Arr(Ar,Ar+ArSize);
cout<< "The Sum is :" <<sum <<endl;
}
int sum_Arr(const int *begin,const int *end)
{
int total=0;
//const int * Pt;
for (const int *Pt=begin;Pt!=end;Pt++)
{
total=total + *Pt;
}
return total;
}
=============
为什么*Pt必须是cons修饰的呢
我找了一会才找到错误的。原来我不是const修饰的。
谢谢