trying to do something simple with pointers and structs

This is just some testing around with structs and pointers. So in this test i am just trying to print out james's best friend, which should be "Kris", but instead of the value being pointed too, i am getting the address of that value being displayed. How do i print out "best_friend" using pointers?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

struct Person
{
	string name;
	Person* best_friend;
};


int main()
{
	Person* chris = new Person;
	(*chris).name = "Kris";
	Person* james = new Person;
	(*james).name = "Jay";
	james->best_friend = chris;
	cout << james->best_friend;
	return 0;
}
Try
cout << james->best_friend->name;

thank you
Topic archived. No new replies allowed.