fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct Node{
  6. int data;
  7. Node(){
  8. data = 0;
  9. std::cout << "Node created. " << this <<endl;
  10. }
  11.  
  12. Node ( const Node& other ) {
  13. data = other.data;
  14. std::cout << "Node copy-constructor. " <<this << " from "<<&other<<endl;
  15. }
  16.  
  17. ~Node(){
  18. std::cout << "Node destroyed. " << this <<endl;
  19. }
  20. };
  21.  
  22. int main() {
  23. vector<Node> vec;
  24. for(int i = 0; i < 2 ; i++)
  25. vec.push_back( *(new Node));
  26. return 0;
  27. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Node created. 0x9a94a10
Node copy-constructor. 0x9a94a20 from 0x9a94a10
Node created. 0x9a94a30
Node copy-constructor. 0x9a94a44 from 0x9a94a30
Node copy-constructor. 0x9a94a40 from 0x9a94a20
Node destroyed. 0x9a94a20
Node destroyed. 0x9a94a40
Node destroyed. 0x9a94a44