Cześć, zrobiłem taka klasę, która mnożny wektor przez skalar.
#include <iostream>
using namespace std;
class wektor
{
public:
int x;
int y;
int z;
wektor(int xd=0, int yd=0, int zd=0): x(xd), y(yd), z(zd) {}
wektor operator* (int liczba)
{
wektor temp;
temp.x=x*liczba;
temp.y=y*liczba;
temp.z=z*liczba;
return temp;
}
};
main()
{
wektor a(1,2,3),
b(5,5,5),
c;
c=a*2;
cout<<c.x<<" "<<c.y<<" "<<c.z<<endl;
}
A gdybym chciał zapisać taką wersję ?
a*2;
Wiem jak to zrobić ale czy można mieć dwie takie możliwości na raz?
void operator* (int liczba)
{
x*=liczba;
y*=liczba;
z*=liczba;
}