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)
{
}
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)
{
}
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.
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.
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.
Are you new to programming in general, or just to C++? If you're new to programming, you probably want to take some classes. If you're just new to C++, you could try reading Practical C++ Programming an on-line C++ Primer.
Regarding your specific question: in the variable declaration, an asterisk means "this is a pointer":
int * pointer;
This also covers function declarations/prototypes, where the variables are declared,as in your example.
After the declaration, asterisk means that you're de-referencing the pointer. That is, you're getting the value at the location to which it's pointing.
printf("memory address:%d value:%d", pointer, *pointer);
You'll note that memory address will change unexpectedly, depending upon the state of the program when it's printed. In a simple program, you won't see the change, but in a complex program, you would.