fork download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <vector>
  5. #include <sstream>
  6.  
  7. class A
  8. {
  9. std::vector<int> n;
  10.  
  11. public :
  12. A();
  13. std::string toString() const;
  14. };
  15.  
  16. A::A()
  17. {
  18. for (int i = 0; i < 10; i++)
  19. n.push_back(std::rand()%10);
  20. }
  21.  
  22. std::string A::toString() const
  23. {
  24. std::ostringstream s;
  25. for (auto i : n)
  26. s << i << ' ';
  27. s << '\n';
  28. return s.str();
  29. }
  30.  
  31. class B
  32. {
  33. A a;
  34.  
  35. public :
  36. void resetA();
  37. A getA() const;
  38. };
  39.  
  40. void B::resetA()
  41. {
  42. a = A();
  43. }
  44.  
  45. A B::getA() const
  46. {
  47. return a;
  48. }
  49.  
  50. int main()
  51. {
  52. srand(time(NULL));
  53.  
  54. B b;
  55. std::cout << b.getA().toString();
  56. b.resetA();
  57. std::cout << b.getA().toString();
  58.  
  59.  
  60. return EXIT_SUCCESS;
  61. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
5 4 5 3 3 6 2 2 5 7 
9 4 8 8 0 8 6 1 2 0