私はオーバーロード演算子を持つ次のクラスを持っています
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
class Cvector
{
public:
int x,y;
Cvector() { x=0;y=0;}
Cvector(int,int);
Cvector operator+(Cvector);
Cvector operator-(Cvector);
int operator*(Cvector);
bool operator==(Cvector);
Cvector operator*(int);
Cvector operator=(Cvector);
int cross_multiplication(Cvector,Cvector);
float norm();
};
Cvector Cvector::operator=(Cvector a)
{
x=a.x;
y=a.y;
return *this;
}
bool Cvector::operator==(Cvector b)
{
return (x==b.x && y==b.y);
}
Cvector Cvector::operator*(int c)
{
Cvector temp;
temp.x=c*x;
temp.y=c*y;
return temp;
}
float Cvector::norm()
{
float result=0;
result+=x*x+y*y;;
return sqrt(result);
}
Cvector::Cvector(int a,int b)
{
x=a;
y=b;
}
Cvector Cvector::operator+(Cvector a)
{
Cvector temp;
temp.x=x+a.x;
temp.y=y+a.y;
return temp;
}
Cvector Cvector::operator-(Cvector b)
{
Cvector temp;
temp.x=x-b.x;
temp.y=y-b.y;
return temp;
}
int Cvector::operator*(Cvector a)
{
return x*a.x+y*a.y;
}
int main()
{
Cvector a(3,4);
Cvector b(4,5);
cout<<b.norm()<<endl;
Cvector c;
c=a*b;
cout<<(a==b)<<endl;
return 0;
}
しかし、それは私に1つのエラーを与えます
1>c:\users\dato\documents\visual studio 2010\projects\point_class\point_class\point_class.cpp(86): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1> c:\users\dato\documents\visual studio 2010\projects\point_class\point_class\point_class.cpp(16): could be 'Cvector Cvector::operator =(Cvector)'
1> while trying to match the argument list '(Cvector, int)'
この問題を解決するのを手伝ってください