Created
September 22, 2014 20:00
-
-
Save saevarb/de782c6e4945104dcdbe to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <cctype> | |
using namespace std; | |
class Person | |
{ | |
public: | |
Person(char* newName, int newAge) : name(newName), age(newAge) { } | |
friend ostream& operator<<(ostream& os, const Person& p); | |
// You'll need to add getters here and change it back to private. | |
char* name; | |
double age; | |
}; | |
ostream& operator<<(ostream& os, const Person& p) | |
{ | |
os << p.name << endl; | |
os << p.age << endl; | |
return os; | |
} | |
int main() | |
{ | |
// Allocate space for 1 pointer | |
Person** people = new Person*[1]; | |
// Allocate one person at first position | |
people[0] = new Person("John", 12); | |
// Alternate: *people = ... | |
// Dereference 'double pointer' and then access the first | |
// element at that pointer. | |
cout << (*people)[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment