fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename T>
  5. struct Base {
  6. int propertyBase;
  7.  
  8. T &setPropertyBase(int propertyBase) {
  9. this->propertyBase = propertyBase;
  10. return (T &) *this;
  11. }
  12. };
  13.  
  14. struct Derived : public Base<Derived> {
  15. int propertyDerived;
  16.  
  17. Derived &setPropertyDerived(int propertyDerived) {
  18. this->propertyDerived = propertyDerived;
  19. return *this;
  20. }
  21. };
  22.  
  23. int main() {
  24. Derived derived = Derived()
  25. .setPropertyDerived(77)
  26. .setPropertyBase(7);
  27. cout << derived.propertyBase << endl;
  28. cout << derived.propertyDerived << endl;
  29. return 0;
  30. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
7
77