Witam mam poniższy kod :
#include <iostream>
#include <cmath>
using namespace std;
class wektor
{
int x, y;
public :
wektor(){}
wektor(int x, int y)
{
this->x = x;
this->y = y;
}
wektor(const wektor &a)
{
cout << "jestem wektor kopiujacy " << endl;
x = 3 * a.x;
y = 3 * a.x;
}
void wypisz() { cout <<" [" << x << "," << y << "]" << endl;}
double dlugosc() {return sqrt(x*x + y*y);}
wektor operator -(void)
{
wektor tmp;
tmp.x = -x;
tmp.y = -y;
return tmp;
}
wektor operator -(int a)
{
wektor tmp;
tmp.x = x - a;
tmp.y = y - a;
return tmp;
}
wektor operator -(wektor &t)
{
wektor ela(0,0);
ela.x = x - t.x;
ela.y = y - t.y;
return ela;
}
friend wektor& operator < (wektor &b1, wektor &b2);
};
wektor& operator < (wektor &b1, wektor &b2)
{
if( b1.dlugosc() < b2.dlugosc() ) return b2;
else return b2;
}
int main()
{
wektor k1(10,10);
wektor k2(k1);
k1.wypisz();
k2.wypisz();
wektor k3 = -k1;
k3.wypisz();
wektor k4 = k1 - 5;
k4.wypisz();
wektor k5 = k1 - k2;
k5.wypisz();
wektor k6 = k1 < k2;
k6.wypisz();
return 0;
}
mam problem z operatorem <, poniewaz nie wiem dlaczego w czasie zwracania włancza sie konstruktor kopiujacy skoro typ zwracany funkcji jest wektor&
Dzięki z góry za pomoc