Write a program to convert basic(data type) to class type.
#include<iostream> using namespace std; class A { private: int x,y; public: A() { x = 54,y = 45; cout << "default constructor" << endl; } A(int t) { x = y = t; } void print() { cout << "x = " << x << " y = " << y << endl; } }; int main() { A ob; int ans = 86; ob.print(); ob = ans; ob.print(); return 0; }
Output
default constructor x = 54 y = 45 x = 86 y = 86