#include <iostream>
#include <string>
using namespace std;
class Person{
private:
string name;
int age, height, weight;
public:
Person(string name = "empty", int age = 0, int height = 0, int weight = 0) {
this->name = name;
this->age = age;
this->height = height;
this->weight = weight;
}
};
class Node {
public:
Person* data;
Node* next;
Node(Person*A) {
data = A;
next = nullptr;
}
};
class LinkedList {
public:
Node * head;
LinkedList() {
head = nullptr;
}
void InsertAtHead(Person*A) {
Node* node = new Node(A);
node->next = head;
head = node;
}
void Print() {
Node* temp = head;
while (temp != nullptr) {
cout << temp->data << " ";
temp = temp->next;
}
cout << endl;
}
};
int main() {
LinkedList* list = new LinkedList();
list->InsertAtHead(new Person("Bob", 22, 145, 70)); list->Print();
}
When I run the Print method my code will print the memory location that Person is being stored. I tried to run through the code with a debugger but I am still confused and I am new to C++ and only a college student. I am guessing this has something to do with my print class and the line specifically "cout << temp->data << " ";" but I am not 100% sure. Could someone please explain how to fix this and why it will work? Thanks in advance!