fork(2) download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T> class ro_prop
  7. {
  8. private:
  9. const function<T()> get;
  10.  
  11. public:
  12. ro_prop(const function<T()> &&get) : get(get) {}
  13. operator T() { return get(); }
  14. };
  15.  
  16. struct rect
  17. {
  18. int width, height;
  19. ro_prop<int> area = ro_prop<int>([this]() { return width * height; });
  20. };
  21.  
  22. int main()
  23. {
  24. rect a { 2, 3 };
  25. int s = a.area;
  26.  
  27. cout << s << endl;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5408KB
stdin
Standard input is empty
stdout
6