Last active
December 28, 2015 01:24
-
-
Save bioball/79f7305926fb6eac8e56 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> | |
using namespace std; | |
template<class T> | |
class LinkedList | |
{ | |
private: | |
T* value; | |
LinkedList* nextNode = nullptr; | |
public: | |
LinkedList (T* val) | |
{ | |
value = val; | |
} | |
LinkedList* next() | |
{ | |
return nextNode; | |
} | |
void append(T* val) | |
{ | |
nextNode = new LinkedList(val); | |
} | |
T* get () | |
{ | |
return value; | |
}; | |
}; | |
class Person | |
{ | |
public: | |
string firstName; | |
string lastName; | |
Person (string fName, string lName) | |
{ | |
firstName = fName; | |
lastName = lName; | |
} | |
}; | |
int main() | |
{ | |
Person peter ("Peter", "Pan"); | |
Person paul ("Paul", "George"); | |
LinkedList<Person> foo (&peter); | |
foo.append(&paul); | |
Person* result = foo.next() -> get(); | |
cout << result->firstName << endl; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment