#include <iostream>
#include <string>
class Point
{
private:
int x, y;
public:
// Normal constructor.
Point(int x1, int y1) {
x = x1; y = y1;
std::cout << ">> Normal constructor called.\n";
}
// Copy constructor.
Point(const Point& p2) {
x = p2.x; y = p2.y;
std::cout << ">> Copy constructor called.\n";
}
std::string Print() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}
};
Point GetPoint() {
Point p(1, 2);
return p;
}
Point GetConstPoint2() {
static Point* p = new Point(1, 2);
return *p;
}
const Point* GetConstPoint3() {
static Point* p = new Point(1, 2);
return p;
}
int main()
{
Point p = GetPoint();
std::cout << ">> " << p.Print() << std::endl;
Point p2 = GetConstPoint2();
std::cout << ">> " << p2.Print() << std::endl;
const Point* p3 = GetConstPoint3();
std::cout << ">> " << p3->Print() << std::endl;
}