Вот этот код
Код:
#include "stdafx.h"
#include "iostream"
#include "math.h"
using namespace std;
class coord{
public:
coord();
coord(int,int);
int Q();
int W();
float dlina();
void out();
friend coord operator-( coord&,int);
friend coord operator-( coord&, coord&);
friend coord operator+( coord&, coord&);
friend coord operator+( coord&,int);
coord& operator=(coord&);
bool operator==( coord&);
bool operator!=( coord&);
bool operator>( coord&);
bool operator<( coord&);
private:
int q,w;
};
coord::coord(){
q=0;
w=0;
}
coord::coord(int a,int b){
q=a;
w=b;
}
void coord::out(){
cout << Q()<< " " << W() << " " <<endl;
}
int coord::Q(){
return q;
}
int coord::W(){
return w;
}
float coord::dlina(){
return sqrt((float)(q*w));
}
coord operator-( coord& i, coord& j){
return coord(i.Q()-j.Q(),i.W()-j.W());
}
coord operator+( coord& i, coord& j){
return coord(i.Q()+j.Q(),i.W()+j.W());
}
coord operator-( coord& i,int j){
return coord(i.Q()-j,i.W()-j);
};
coord operator+( coord& i,int j){
return coord(i.Q()+j,i.W()+j);
};
bool coord::operator==( coord& b){
if(q==b.q&&w==b.w) return 1;
else return 0;
}
bool coord::operator!=( coord& b){
if(q==b.q&&w==b.w) return 0;
else return 1;
}
bool coord::operator>( coord& b){
if(dlina()>b.dlina()) return 1;
else return 0;
}
bool coord::operator<( coord& b){
if(dlina()<b.dlina()) return 1;
else return 0;
}
coord& coord::operator=(coord& a){
q=a.q;
w=a.w;
return *this;
}
int main()
{
int z,zz;
coord a();
coord b();
coord c();
cout << "Enter 2D coordinates A"<<endl;
cin >> z >> zz;
a(z,zz);
cout <<"Enter 2D coordinates B"<<endl;
cin >> z >> zz;
b(z,zz);
cout << " A: ";
a.out();
cout << " B: ";
b.out();
c=a+b;
cout << " A+B: ";
c.out();
c=a-b;
cout << " A-B: ";
c.out();
c=a+100;
cout << " A+100: ";
c=a+100;
c.out;
cout << " B-100: ";
c=b-100;
c.out;
if(a==b) cout << "A=B "<<endl;
if(a!=b) cout << "A!=B "<<endl;
if(a>b) cout << "A>B "<<endl;
if(a<b) cout << "A<B "<<endl;
system("pause");
return 0;
}
Дает ошибки
Код:
1>------ Build started: Project: laba3, Configuration: Debug Win32 ------
1> laba3.cpp
1>laba3.cpp(96): error C2660: 'a' : function does not take 2 arguments
1>laba3.cpp(99): error C2660: 'b' : function does not take 2 arguments
1>laba3.cpp(101): error C2228: left of '.out' must have class/struct/union
1>laba3.cpp(103): error C2228: left of '.out' must have class/struct/union
1>laba3.cpp(104): error C2296: '+' : illegal, left operand has type 'coord (__cdecl *)(void)'
1>laba3.cpp(106): error C2228: left of '.out' must have class/struct/union
1>laba3.cpp(107): error C2296: '-' : illegal, left operand has type 'coord (__cdecl *)(void)'
1>laba3.cpp(109): error C2228: left of '.out' must have class/struct/union
1>laba3.cpp(110): error C2296: '+' : illegal, left operand has type 'coord (__cdecl *)(void)'
1>laba3.cpp(112): error C2296: '+' : illegal, left operand has type 'coord (__cdecl *)(void)'
1>laba3.cpp(113): error C2228: left of '.out' must have class/struct/union
1>laba3.cpp(115): error C2296: '-' : illegal, left operand has type 'coord (__cdecl *)(void)'
1>laba3.cpp(116): error C2228: left of '.out' must have class/struct/union
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Подскажите что не так
Что то с переопределением + и -
Ругается на 2 параметра в конструкторе. хотя такой конструктор определен
Что то с объектом с .. компилятор в нем не признает объект класса