主题:求教~~~~
#include <iostream >
using namespace std;
template <class T>//声明函数模板
void outputarray(const T *p, const int count)//这里为什么要用const???
{
for(int i=0;i<count;i++)
cout<<p[i]<<" ";
cout<<endl;
}
int main()
{
const int a=8,b=8,c=20;//这里为什么要用const?
int aarray[a]={1,2,3,4,5,6,7,8};
double barray[b]={1.1,2.2,4.55,34.3,4.5,234.2,56.2,3.3};
char carray[c]="welcome to see you!";
cout<<"a:"<<endl<<endl;
outputarray(aarray,a);
cout<<"b:"<<endl<<endl;
outputarray(barray,b);
cout<<"c:"<<endl<<endl;
outputarray(carray,c);
return 0;
}
如果上述两个const去掉就是错误,为什么????
谢谢指教~~~~
using namespace std;
template <class T>//声明函数模板
void outputarray(const T *p, const int count)//这里为什么要用const???
{
for(int i=0;i<count;i++)
cout<<p[i]<<" ";
cout<<endl;
}
int main()
{
const int a=8,b=8,c=20;//这里为什么要用const?
int aarray[a]={1,2,3,4,5,6,7,8};
double barray[b]={1.1,2.2,4.55,34.3,4.5,234.2,56.2,3.3};
char carray[c]="welcome to see you!";
cout<<"a:"<<endl<<endl;
outputarray(aarray,a);
cout<<"b:"<<endl<<endl;
outputarray(barray,b);
cout<<"c:"<<endl<<endl;
outputarray(carray,c);
return 0;
}
如果上述两个const去掉就是错误,为什么????
谢谢指教~~~~