#include
class Point2D {
protected:
int x, y;
public:
Point2D (int x1, int y1);
void print ();
};
class Point3D : public Point2D {
private:
int z;
public:
Point3D (int x1, int y1, int z1);
void print ();
};
Point2D::Point2D (int x1, int y1) { x = x1; y = y1; }
void Point2D::print () { cout << x << " " << y << endl; }
Point3D::Point3D (int x1, int y1, int z1) : Point2D (x1, y1) { z = z1; }
void Point3D::print () { cout << x << " " << y << " " << z << endl; }
int main () {
Point2D pt2d (1,2);
Point3D pt3d (10,20,30);
pt2d.print();
pt3d.print();
pt2d = pt3d;
pt2d.print();
return 0;
}
See the output of this program