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