Created
May 19, 2017 15:03
-
-
Save ramachandrajr/241d35057d8c1b317d36ebcc0b9e390b to your computer and use it in GitHub Desktop.
Fixing error with pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Person | |
{ | |
public: | |
string name; | |
int age; | |
double height; | |
double weight; | |
}; | |
void ModifyPerson(Person *pOne); | |
int main() { | |
// Person 1 | |
Person person1; | |
person1.name="Tom"; | |
person1.age=25; | |
person1.height=175.0; | |
person1.weight=120.8; | |
// pOne | |
Person *pOne = new Person; | |
*pOne = person1; | |
cout << person1.name <<endl; | |
ModifyPerson(pOne); | |
person1=*pOne; | |
cout << person1.name <<endl; | |
return 0; | |
} | |
void ModifyPerson(Person *pOne) | |
{ | |
// Create a person pointer. | |
Person *person1; | |
// Put the memory location from pone into person1. | |
person1 = pOne; | |
// Manipulate data at that memory location | |
person1->name = "Tomnew"; | |
cout << "in ModifyPerson():" << person1->name << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment