fork download
  1. #include <memory>
  2. #include <vector>
  3. #include <string>
  4. #include <iostream>
  5. #include <cstdio>
  6.  
  7. class Hoge {
  8. public:
  9. std::string s;
  10. Hoge() { s = "abcdef"; }
  11. Hoge(int i) {
  12. char buf[5];
  13. std::sprintf(buf, "%d", i);
  14. s = std::string("abcdef") + buf;
  15. }
  16. Hoge(const std::string& str) { s = str; std::cout <<"set: " << s << std::endl; }
  17. ~Hoge() { std::cout<<"del: "<< s << std::endl; }
  18. void out() { std::cout <<"func: "<< s << std::endl; }
  19. };
  20.  
  21. typedef std::vector<std::unique_ptr<Hoge>> Vuh;
  22.  
  23. Vuh getHogeArr() {
  24. const int N = 100;
  25. Vuh vHoge;
  26.  
  27. for (int i = 0; i < N; i++)
  28. vHoge.push_back(std::unique_ptr<Hoge>(new Hoge(i)));
  29.  
  30. return vHoge;
  31. }
  32.  
  33. int main()
  34. {
  35. Vuh v = getHogeArr();
  36.  
  37. for (auto& i : v)
  38. i->out();
  39. }
  40.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
func: abcdef0
func: abcdef1
func: abcdef2
func: abcdef3
func: abcdef4
func: abcdef5
func: abcdef6
func: abcdef7
func: abcdef8
func: abcdef9
func: abcdef10
func: abcdef11
func: abcdef12
func: abcdef13
func: abcdef14
func: abcdef15
func: abcdef16
func: abcdef17
func: abcdef18
func: abcdef19
func: abcdef20
func: abcdef21
func: abcdef22
func: abcdef23
func: abcdef24
func: abcdef25
func: abcdef26
func: abcdef27
func: abcdef28
func: abcdef29
func: abcdef30
func: abcdef31
func: abcdef32
func: abcdef33
func: abcdef34
func: abcdef35
func: abcdef36
func: abcdef37
func: abcdef38
func: abcdef39
func: abcdef40
func: abcdef41
func: abcdef42
func: abcdef43
func: abcdef44
func: abcdef45
func: abcdef46
func: abcdef47
func: abcdef48
func: abcdef49
func: abcdef50
func: abcdef51
func: abcdef52
func: abcdef53
func: abcdef54
func: abcdef55
func: abcdef56
func: abcdef57
func: abcdef58
func: abcdef59
func: abcdef60
func: abcdef61
func: abcdef62
func: abcdef63
func: abcdef64
func: abcdef65
func: abcdef66
func: abcdef67
func: abcdef68
func: abcdef69
func: abcdef70
func: abcdef71
func: abcdef72
func: abcdef73
func: abcdef74
func: abcdef75
func: abcdef76
func: abcdef77
func: abcdef78
func: abcdef79
func: abcdef80
func: abcdef81
func: abcdef82
func: abcdef83
func: abcdef84
func: abcdef85
func: abcdef86
func: abcdef87
func: abcdef88
func: abcdef89
func: abcdef90
func: abcdef91
func: abcdef92
func: abcdef93
func: abcdef94
func: abcdef95
func: abcdef96
func: abcdef97
func: abcdef98
func: abcdef99
del: abcdef0
del: abcdef1
del: abcdef2
del: abcdef3
del: abcdef4
del: abcdef5
del: abcdef6
del: abcdef7
del: abcdef8
del: abcdef9
del: abcdef10
del: abcdef11
del: abcdef12
del: abcdef13
del: abcdef14
del: abcdef15
del: abcdef16
del: abcdef17
del: abcdef18
del: abcdef19
del: abcdef20
del: abcdef21
del: abcdef22
del: abcdef23
del: abcdef24
del: abcdef25
del: abcdef26
del: abcdef27
del: abcdef28
del: abcdef29
del: abcdef30
del: abcdef31
del: abcdef32
del: abcdef33
del: abcdef34
del: abcdef35
del: abcdef36
del: abcdef37
del: abcdef38
del: abcdef39
del: abcdef40
del: abcdef41
del: abcdef42
del: abcdef43
del: abcdef44
del: abcdef45
del: abcdef46
del: abcdef47
del: abcdef48
del: abcdef49
del: abcdef50
del: abcdef51
del: abcdef52
del: abcdef53
del: abcdef54
del: abcdef55
del: abcdef56
del: abcdef57
del: abcdef58
del: abcdef59
del: abcdef60
del: abcdef61
del: abcdef62
del: abcdef63
del: abcdef64
del: abcdef65
del: abcdef66
del: abcdef67
del: abcdef68
del: abcdef69
del: abcdef70
del: abcdef71
del: abcdef72
del: abcdef73
del: abcdef74
del: abcdef75
del: abcdef76
del: abcdef77
del: abcdef78
del: abcdef79
del: abcdef80
del: abcdef81
del: abcdef82
del: abcdef83
del: abcdef84
del: abcdef85
del: abcdef86
del: abcdef87
del: abcdef88
del: abcdef89
del: abcdef90
del: abcdef91
del: abcdef92
del: abcdef93
del: abcdef94
del: abcdef95
del: abcdef96
del: abcdef97
del: abcdef98
del: abcdef99