fork download
  1. #include <vector>
  2. #include <memory>
  3.  
  4. using namespace std;
  5.  
  6. class Base
  7. {
  8. public:
  9. int getVal() { return 0; }
  10. };
  11.  
  12. int getVal(shared_ptr<Base>& p)
  13. {
  14. return p->getVal();
  15. }
  16.  
  17. int getVal(unique_ptr<Base>& p)
  18. {
  19. return p->getVal();
  20. }
  21.  
  22. int getVal(int*& p)
  23. {
  24. return *p;
  25. }
  26.  
  27.  
  28. template <class Type>
  29. bool writeRecordForSet(std::vector<Type>& entityPtr)
  30. {
  31. if (entityPtr.size() == 0)
  32. return true;
  33. //...
  34. for (auto iter = entityPtr.begin(); iter != entityPtr.end(); iter++) {
  35. int myval = getVal(*iter);
  36. }
  37.  
  38. return true;
  39. }
  40.  
  41. int main()
  42. {
  43. std::vector<std::shared_ptr<Base>> vec_shared;
  44. std::vector<int*> vec_intp;
  45. std::vector<std::unique_ptr<Base>> vec_unique_ptr;
  46. writeRecordForSet(vec_shared);
  47. writeRecordForSet(vec_intp);
  48. writeRecordForSet(vec_unique_ptr);
  49. }
  50.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty