Advertisement
Guest User

Type cast

a guest
Jan 20th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class type2 {
  6. public:
  7. int a, b;
  8. type2(int a, int b): a(a), b(b) { }
  9. };
  10.  
  11. class type1 {
  12. public:
  13. int ab;
  14. type1(int ab): ab(ab) { }
  15. type1(type2 t) {
  16. ab = t.a * t.b;
  17. }
  18. };
  19.  
  20. int main() {
  21. type2 t2(3, 4);
  22. cout << t2.a << " " << t2.b << endl;
  23. cout << ((type1)t2).ab << endl;
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement