fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. struct Guy ;
  5.  
  6. struct Girl
  7. {
  8. Girl( Guy* g = 0 ) : boyfriend(g) {}
  9. Guy* boyfriend ;
  10. };
  11.  
  12. struct Guy
  13. {
  14. Guy( const std::string& n ) : name(n) {}
  15. const std::string name ;
  16. // ...
  17. };
  18.  
  19. int main()
  20. {
  21. Guy a( "a") ;
  22.  
  23. Girl b( &a ) ;
  24. if( b.boyfriend ) std::cout << b.boyfriend->name << '\n' ;
  25.  
  26. Guy c( "c" ) ;
  27. b.boyfriend = &c ;
  28. if( b.boyfriend ) std::cout << b.boyfriend->name << '\n' ;
  29.  
  30. b.boyfriend = 0 ;
  31. if( b.boyfriend ) std::cout << b.boyfriend->name << '\n' ;
  32. }
  33.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
a
c