fork download
  1. #include <stdio.h>
  2.  
  3. struct rectangleBase
  4. {
  5. int width, height;
  6. int posX, posY;
  7. };
  8.  
  9. struct circleBase
  10. {
  11. int radius;
  12. int posX, posY;
  13. };
  14.  
  15. template<typename T>
  16. class Object {
  17. public:
  18.  
  19. Object() { }
  20. ~Object() { }
  21.  
  22. void movePos(int x, int y)
  23. {
  24. object.posX += x;
  25. object.posY += y;
  26. }
  27.  
  28. void setPos(int x, int y)
  29. {
  30. object.posX = x;
  31. object.posY = y;
  32. }
  33.  
  34. T& returnObject() { return object; }
  35.  
  36. private:
  37. T object;
  38. };
  39.  
  40. int main(int argc, char ** argv)
  41. {
  42. Object<rectangleBase> a;
  43. Object<circleBase> b;
  44. b.setPos(1,2);
  45. printf("px: %d", b.returnObject().posX);
  46. }
  47.  
  48.  
  49.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
px: 1