fork(1) 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. one = two;
  31. }
  32.  
  33. void Test(string result)
  34. {
  35. shared_ptr<Thing> one(new Thing());
  36. shared_ptr<Thing> two(new Thing());
  37. Foo(one, two);
  38.  
  39. assert(one->getName() == result);
  40. }
  41.  
  42. int main() {
  43. Test("foo");
  44. Test("bar");
  45.  
  46. return 0;
  47. }
Runtime error #stdin #stdout #stderr 0s 3276KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog: prog.cpp:39: void Test(std::string): Assertion `one->getName() == result' failed.