fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A
  5. {
  6. int a;
  7. };
  8.  
  9. struct B
  10. {
  11. int b;
  12. };
  13.  
  14. struct C : public A,B
  15. {
  16. int c;
  17. };
  18.  
  19. template<class T>
  20. void addToObj(T& t)
  21. {
  22. t.a += 10;
  23. }
  24.  
  25. void addToObj(C& a)
  26. {
  27.  
  28. addToObj<C>(a);
  29.  
  30. a.a += 20;
  31. }
  32.  
  33. int main()
  34. {
  35. C c;
  36.  
  37. c.a = 10;
  38. c.b = 11;
  39. c.c = 12;
  40.  
  41. addToObj(c);
  42.  
  43. std::cout << c.a << ":" << c.b << ":" << c.c << std::endl;
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
40:11:12