fork(1) download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. class Point1 {
  6. public:
  7. int x;
  8. int y;
  9.  
  10. Point1(int x, int y);
  11. ~Point1();
  12. };
  13.  
  14. Point1::Point1(int x1, int y1) {
  15. x = x1;
  16. y = y1;
  17. cout << "criou" << endl; //estou deixando só para fins didáticos
  18. }
  19.  
  20. Point1::~Point1() {
  21. cout << "destruiu " << x << " " << y << endl; //para fins de debug
  22. }
  23.  
  24. unique_ptr<Point1> retorno() {
  25. unique_ptr<Point1> C(new Point1(1,4));
  26. return C;
  27. }
  28.  
  29. int main() {
  30. auto C = retorno();
  31. cout << C->x << endl;
  32. cout << C->y << endl;
  33. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
criou
1
4
destruiu 1 4