#include<iostream>
usingnamespace std;
class Point {
float x;
float y;
public:
Point(float x=0, float y=0) {this->x = x; this->y = y;}
Point (const Point& p) { x = p.x; y = p.y;}
~Point() { }
void Print() const { cout << "(" << x << ", " << y <<")"; }
Point operator-() {
Point result (-x, -y);
return result;
}
Point operator*(float number) {
Point result (number*x, number*y);
return result;
}
friend Point operator*(float number, const Point& p);
};
Point operator*(float number, const Point& p) {
Point result (number*p.x, number*p.y);
return result;
}
int main () {
Point P(1,3);
P.Print();
Point Q = -P;
Q.Print();
Point R = 2*P;
R.Print();
Point T = P*2;
T.Print();
return 0;
}
I am very new to object oriented programming, so if someone could edit this code with explanation comments in every line it would be very helpful, i need to know more about pointers and destructors and how do they work. Thank you.
There are no pointers used anywhere in the code you've posted (except for this which is only used because whoever wrote the code didn't think more carefully about using helpful names for their variables).
The destructor in the Point class does absolutely nothing.
If you want to learn about pointers and destructors, this isn't really a helpful example of code to learn about them from!
Can you be specific about which bits of the code you don't understand?