Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Point3D;
- class Point
- {
- int x;
- int y;
- public:
- Point() = default;
- Point(int pX, int pY) : x{ pX }, y{ pY } {}
- Point& setX(int pX) { x = pX; return *this; }
- Point& setY(int pY) { y = pY; return *this; }
- void showPoint() const
- {
- std::cout << '(' << x << ',' << y << ')';
- }
- explicit operator bool() const { return x and y; }
- explicit operator Point3D() const;
- };
- class Point3D
- {
- int x;
- int y;
- int z;
- public:
- Point3D() = default;
- Point3D(int pX, int pY, int pZ) : x{ pX }, y{ pY }, z{ pZ } {}
- Point3D& setX(int pX) { x = pX; return *this; }
- Point3D& setY(int pY) { y = pY; return *this; }
- Point3D& setZ(int pZ) { z = pZ; return *this; }
- void showPoint() const
- {
- std::cout << '(' << x << ',' << y << ',' << z << ')';
- }
- explicit operator bool() const { return x and y and z; }
- explicit operator Point() const;
- };
- Point::operator Point3D() const { return { x,y,0 }; }
- Point3D::operator Point() const { return { x, y }; }
- int main()
- {
- const int pointsCount{ 3 };
- Point points[pointsCount]{ {0,0}, {28,29}, {0,26} };
- bool isZero{};
- for (auto point{ points }, pointsEnd{ points + pointsCount }; point != pointsEnd; ++point)
- {
- //isZero = (bool)(*point);
- if (!*point)
- {
- point->showPoint();
- std::cout << '\n';
- }
- else
- {
- std::cout << "Zero Point detected!\n";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment