thespeedracer38

Class type to Basic Type conversion

Feb 11th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. /* Conversion from Class Type to Basic Type `*/
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. class C{
  9.     int m;
  10.     public:
  11.         C(int);
  12.         ~C();
  13.         operator int();
  14. };
  15.  
  16. inline C::C(int m){
  17.     C::m = m;
  18. }
  19.  
  20. inline C::~C(){
  21.     cout << "Destructor Called" << endl;
  22. }
  23.  
  24. inline C::operator int(){
  25.     return m;
  26. }
  27.  
  28. int main() {
  29.     C obj(6);
  30.     int a = obj;
  31.     cout << "a = " << a << endl;
  32.     cin.get();
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment