|
下面这个程序,我在vc里面编译,执行结果是正确的,而用g++编译运行就错误,1.3.1和1.3.5都错误,而且错的不一样
//to check if the x belongs to array a
//this program compiles well using MSVC, however mistaken using gcc 1.3.1 and 1.3.5
#include <iostream>
using namespace std;
template<class T>
bool belongto(T list[],int i,int n,T x)
{
if(i==n)
{
return false;
}
else
{
if(x==list)
return true;
else
belongto(list,i+1,n,x);
}
}
int main()
{
char a[]={'h','e','l','l','o'};
if(belongto(a,0,5,'w'))
cout<<"char 'w' belongs to \"hello\""<<endl;
if(belongto(a,0,5,'e'))
cout<<"char 'o' belogs to \"hello\""<<endl;
return 0;
} |
|