Write a program to convert class to class(type conversion).
#include<iostream> using namespace std; class A { private: int x,y; public: A():x(10),y(30){} int& get_x() { return x; } int& get_y() { return y; } void print() { cout << "x = " << x << " y = " << y << endl; } }; class B { private: int a,b; public: B():a(20),b(40){} B(A& ob) { a = ob.get_x(); b = ob.get_y(); } void print() { cout << "a = " << a << " b = " << b << endl; } }; int main() { A oba; B obb; oba.print(); obb.print(); obb = oba; oba.print(); obb.print(); return 0; }
Output
x = 10 y = 30 a = 20 b = 40 x = 10 y = 30 a = 10 b = 30