Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

但实际上我在VS2008上运行时完全没有问题!!!????网站却上显示的错误:no operator found which takes a right-hand operand of type 'T' (or there is no acceptable conversion)

Posted by 2008fanyanjun2008 at 2009-10-13 16:42:45 on Problem 1060
网站上显示的错误:
Main.cpp
Main.cpp(99) : error C2679: binary '*' : no operator found which takes a right-hand operand of type 'T' (or there is no acceptable conversion)
        Main.cpp(13): could be 'T operator *(T &,T &)' [found using argument-dependent lookup]
        Main.cpp(13): or       'T operator *(T &,T &)' [found using argument-dependent lookup]
        while trying to match the argument list '(T, T)'
Main.cpp(101) : error C2679: binary '*' : no operator found which takes a right-hand operand of type 'T' (or there is no acceptable conversion)
        Main.cpp(13): could be 'T operator *(T &,T &)' [found using argument-dependent lookup]
        Main.cpp(13): or       'T operator *(T &,T &)' [found using argument-dependent lookup]
        while trying to match the argument list '(T, T)'
Main.cpp(115) : error C2664: 'modulo' : cannot convert parameter 1 from 'T' to 'T &'
        A non-const reference may only be bound to an lvalue

但实际上我在VS2008上运行时完全没有问题!!!????


源代码如下:

#include<iostream>
using namespace std;


const int MAX=128;
class T{
public:
	int t[MAX];
	T(){for(int i=0;i<MAX;i++)t[i]=0;}
	T(T& c){for(int j=0;j<MAX;j++)t[j]=0;for(int i=0;i<=c.t[0]&&c.t[i]>=0;i++)t[i]=c.t[i];}
	~T(){for(int i=0;i<=t[0]&&t[i]>=0;i++)t[i]=-1;}
	friend T operator+(T&,T&);
	friend T operator-(T&,T&);
	friend T operator*(T&,T&);
	friend T& modulo(T&,T&);
	friend T& CheckChange(T& c);
	friend T Creat(T& a,T& b);
};

T& CheckChange(T& c){//全在非全零的情况下做!
	int i=1;
	for(;i<=c.t[0];i++)if(c.t[i])break;
	if(i==1)return c;
	c.t[0]=c.t[0]-i+1;
	for(int k=1;k<=c.t[0];k++)c.t[k]=c.t[k+i-1];
	return c;
}

T operator+(T& a,T& b){
	T c;
	if(a.t[0]>=b.t[0]){
		int i=a.t[0]-b.t[0];c.t[0]=a.t[0];
		for(int j=1;j<=b.t[0];j++){
			c.t[j]=a.t[j+i]^b.t[j];
		}
	}
	else {
		int i=b.t[0]-a.t[0];c.t[0]=b.t[0];
		for(int j=1;j<=a.t[0];j++){
			c.t[j]=a.t[j+i]^b.t[j];
		}
	
	}
	CheckChange(c);
	return c;	
}

T operator-(T& a,T& b){
	T c;
	if(a.t[0]>=b.t[0]){
		int i=a.t[0]-b.t[0];
		for(int k=0;k<=i;k++)c.t[i]=a.t[i];
		for(int j=1;j<=b.t[0];j++){
			c.t[j+i]=a.t[j+i]^b.t[j];
		}
	}
	else {
		int i=b.t[0]-a.t[0];
		for(int k=0;k<=i;k++)c.t[i]=b.t[i];
		for(int j=1;j<=a.t[0];j++){
			c.t[j+i]=b.t[j+i]^a.t[j];
		}
	
	}
	CheckChange(c);
	return c;
}


T operator * (T& a,T& b){
	T c;
	c.t[0]=a.t[0]+b.t[0]-1;
	int k;
	for(int i=1;i<=a.t[0];i++)
		for(int j=1;j<=b.t[0];j++){
			k=i+j-1;
			c.t[k]=c.t[k]^(a.t[i]*b.t[j]);/////
		}
	CheckChange(c);
	return c;
}

T Creat(T& a,T& b){//假定a的度大于=b!
	T c;
	c.t[0]=a.t[0]-b.t[0]+1;
	c.t[1]=1;
	for(int i=2;i<=c.t[0];i++)c.t[i]=0;
	return c;
}

bool ifcontinue(const T& a,const T&b){
	int i=2;
	for(;i<=a.t[0]&&a.t[i]==b.t[i];i++);
	if(i>a.t[0]||a.t[i]>b.t[i])return true;
	else return false;
}

T& modulo(T& a,T& b){//假定a的度大于=b!
	while(a.t[0]>b.t[0]){
		a=a-b*Creat(a,b);
	}
	if(a.t[0]==b.t[0]&&ifcontinue(a,b))a=a-b*Creat(a,b);
	return a;
}

int main(){
	T a,b,h,c;
	int n;cin>>n;
	for(int y=0;y<n;y++){
		for(int d=0;d<=a.t[0];d++)cin>>a.t[d];
		for(int l=0;l<=b.t[0];l++)cin>>b.t[l];
		for(int i=0;i<=h.t[0];i++)cin>>h.t[i];
		if(!h.t[0]){
			cerr<<"wrong!"<<endl;return 0;
		}
		c=modulo(a*b,h);
		for(int j=0;j<=c.t[0];j++)cout<<c.t[j]<<' ';
		cout<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator