fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<class T>
  5. class Obj {
  6. private:
  7. T a;
  8. public:
  9. Obj(T a_) : a(a_) {}
  10.  
  11. const T& getA() const { return a; }
  12. };
  13.  
  14. int main() {
  15. std::vector<Obj<int>> objs;
  16.  
  17. objs.push_back(Obj<int>(5));
  18. objs.push_back(Obj<int>(10));
  19. objs.push_back(Obj<int>(15));
  20. objs.push_back(Obj<int>(20));
  21.  
  22. for(Obj<int> &obj : objs) {
  23. std::cout << obj.getA() << "\n";
  24. }
  25.  
  26. std::cout << std::flush;
  27. return 0;
  28. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
5
10
15
20