fork download
  1. #include <iostream>
  2. #include <cassert>
  3. #include <memory>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. class Thing {
  9. string name;
  10.  
  11. public:
  12.  
  13. Thing(): name() {
  14. // nop
  15. }
  16.  
  17. void setName(const string name) {
  18. this->name = name;
  19. }
  20.  
  21. const string getName() {
  22. return this->name;
  23. }
  24. };
  25.  
  26. void Foo(shared_ptr<Thing> one, shared_ptr<Thing> two)
  27. {
  28. one->setName("foo");
  29. }
  30.  
  31. void Test()
  32. {
  33. shared_ptr<Thing> one(new Thing());
  34. shared_ptr<Thing> two(new Thing());
  35. Foo(one, two);
  36.  
  37. assert(one->getName() == "foo");
  38. }
  39.  
  40. int main() {
  41. Test();
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
Standard output is empty