fork download
  1. #include <iostream>
  2. class B{
  3. public:
  4. B(int xx, int yy): x(xx), y(yy){}
  5. B& operator+(B& d){
  6. x+=d.x;
  7. y+=d.y;
  8. return *this;
  9. }
  10. private:
  11. int x;
  12. int y;
  13. };
  14. class A{
  15. public:
  16. A(int xx, int yy): x(xx), y(yy){}
  17. operator B() {
  18. return B(x,y);
  19. }
  20. operator int() {
  21. return x;
  22. }
  23.  
  24. private:
  25. int x;
  26. int y;
  27. };
  28.  
  29. int main() {
  30. A a(4 ,5);
  31. B b(3,2);
  32. static_cast<B>(a) + b;
  33. return 0;
  34. }
Success #stdin #stdout 0s 4416KB
stdin
Standard input is empty
stdout
Standard output is empty