Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4. class People {
  5. public:
  6.     string name;
  7.     People(string name) {
  8.         People::name=name;
  9.     }
  10.     void setName(string name) {
  11.         People::name=name;
  12.     }
  13.     string getName() {
  14.         return People::name;
  15.     }
  16. };
  17.  
  18. void invalidRef(People);
  19. void validRef(People*);
  20.  
  21. int main() {
  22.     People p1("p1");
  23.     cout <<&p1<<endl;
  24.     invalidRef(p1);
  25.     validRef(&p1);
  26.     return 0;
  27. }
  28.  
  29. void invalidRef(People p) {
  30.     //In this case, object address is overridden by the local variable
  31.     cout <<&p<<endl;
  32. }
  33.  
  34. void validRef(People* _p) {
  35.     cout <<_p<<endl;
  36. }