fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct foo {
  5. float val;
  6.  
  7. foo(float val): val(val){}
  8.  
  9. foo &operator+=(foo const &other) {
  10. this->val += other.val;
  11. return *this;
  12. }
  13.  
  14. friend foo operator*(foo const &lhs, foo const &rhs) {
  15. return lhs.val*rhs.val;
  16. }
  17. };
  18.  
  19. int main() {
  20. foo a = 5, b = 6;
  21. a += b * 3;
  22. cout << a.val << endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
23