Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding c++ code; what do *datatype and classname::method mean?

Tags:

c++

c

I am new to C++ and I am trying to understand some code. What does it mean to have a * in front of the datatype ? and why is the class Name in front of the method name CAStar::LinkChild

void CAStar::LinkChild(_asNode *node, _asNode *temp)
{

}
like image 306
numerical25 Avatar asked Feb 19 '10 01:02

numerical25


2 Answers

  1. A * in front of the data type says that the variable is a pointer to the data type, in this case, a pointer to a node. Instead of passing a copy of the entire "node" into the method, a memory address, or pointer, is passed in instead. For details, see Pointers in this C++ Tutorial.

  2. The class name in front of the method name specifies that this is defining a method of the CAStar class. For details, see the Tutorial pages for Classes.

like image 199
Reed Copsey Avatar answered Sep 27 '22 00:09

Reed Copsey


The * means that it's a pointer. You will also find that _asNode *node is equivalent to _asNode* node.

The class name is in front of the method name when the method is not defined inside the class { ... }. The :: is the scope operator.

like image 45
David Johnstone Avatar answered Sep 27 '22 00:09

David Johnstone