Skip to content

Instantly share code, notes, and snippets.

@saevarb
Created September 22, 2014 20:00
Show Gist options
  • Save saevarb/de782c6e4945104dcdbe to your computer and use it in GitHub Desktop.
Save saevarb/de782c6e4945104dcdbe to your computer and use it in GitHub Desktop.
#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