fork download
  1. struct ListItem
  2. {
  3. ListItem* GetPrev () { return nullptr; }
  4. ListItem* GetNext () { return nullptr; }
  5. // ... and many more
  6. };
  7.  
  8. template <typename T>
  9. struct ListItemT : ListItem
  10. {
  11. T* GetPrev () { return static_cast<T*>(ListItem::GetPrev()); }
  12. T* GetNext () { return static_cast<T*>(ListItem::GetNext()); }
  13. };
  14.  
  15. struct One : ListItemT<One>
  16. {
  17. };
  18.  
  19. class Two : public ListItemT<Two>
  20. {
  21. };
  22.  
  23. class Object : public One, public Two
  24. {
  25. };
  26.  
  27. int main() {
  28. Object o;
  29. One* prev = o.One::GetPrev();
  30. // your code goes here
  31. return 0;
  32. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty