Hi everyone, I just can't seem to find an explanation for using this "->" in code, in C++. I've migrated from Java and C#, and haven't seen this notation before. Basic example:

CMesh *pMesh = WorldObjects[i]->m_pMesh;

As best as I can tell, this is the C++ equivalent of C#'s

WorldObjects[i].m_pMesh;

. (as if to say that m_pMesh is a member variable, or method of the WorldObjects object, but as it is only a code snippet, I cant check the classes to see)

Just a quick syntactic explanation is all I need. Thanks.

For a class or a struct that's being referred to by a pointer, -> represents the dereference of the pointer followed by a dot operator.

For example say you have a class MyClass and public member function myMethod:

MyClass * mycl = new MyClass();
mycl->myMethod();
would be the same as
(*mycl).myMethod();

Edited 6 Years Ago by jonsca: n/a

For a class or a struct that's being referred to by a pointer, -> represents the dereference of the pointer followed by a dot operator.

For example say you have a class MyClass and public member function myMethod:

MyClass * mycl = new MyClass();
mycl->myMethod();
would be the same as
(*mycl).myMethod();

Thanks so much, that takes ALL the confusion out of it. The worst part was trying to google "->" - Google didnt seem to recognise that as a search term, lol.

Thanks!

The worst part was trying to google "->"

Yeah, I've been through that myself. I've never found a way around it.

This article has been dead for over six months. Start a new discussion instead.