What exactly is a pointer?

Man, I had the & symbol backwards. I thought it de-referenced. No wonder I’ve found sticking it randomly in places I don’t expect fixes stuff! :slight_smile: So, is & the same as * when it’s inline? eg:

MyType MyThing = new MyType();
return *MyThing;

…is the same as:

MyType * MyThing = new MyType();
return MyThing;

…and is the same as:

MyType MyThing = new MyType();
return &MyThing;

Is that right?

The logic I’d had explained to me is “prefer * but you can resort to & after the fact”. Now that makes sense.

One more thing that catches new people out that I’ve learnt: if your variable is a pointer to an object rather than the object itself, you access members using a dereferencing joiner (->) instead of a period (.) eg:

MyThing->DoStuff() (where MyThing is a pointer)
MyThing.DoStuff() (where MyThing is a local object)

VS tries to convert to -> for you but sometimes it’s wrong and you have to hit backspace to get your period back.