fork(1) download
  1. #include <iostream>
  2.  
  3. typedef struct A
  4. {
  5. int x;
  6. int y;
  7. } *PA;
  8.  
  9. class B
  10. {
  11. public:
  12. B(PA pa):m_pa(pa){}
  13. int getPa() const{return m_pa->x;}
  14. private:
  15. PA m_pa;
  16. };
  17.  
  18. void func(const B& b)
  19. {
  20. std::cout << b.getPa();
  21. }
  22.  
  23. int main()
  24. {
  25. A a = {5,7};
  26. PA pA = &a;
  27.  
  28. func(pA); //Why does this compile and what is the outcome??
  29. return 0;
  30. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
5