Understanding C ++ code; What is * data type and class name :: method?

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

 void CAStar::LinkChild(_asNode *node, _asNode *temp) { } 
+6
c ++ c
source share
3 answers
  • A * before the data type says that the variable is a pointer to a data type, in this case a pointer to a node. Instead of passing a copy of the entire "node" to this method, a memory address or pointer is passed instead. See Pointers in this C ++ tutorial for more details.

  • The class name before the method name indicates that this defines the method of the CAStar class. See the Learning Pages for Classes for more information.

+6
source share

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

The class name appears before the method name when the method is not defined inside class { ... } . :: is the operator.

+3
source share

Are you new to programming in general or just C ++? If you are new to programming, you probably want to take some classes. If you're just not familiar with C ++, you can try reading Practical C ++ Programming in C ++ Primer Online Mode.

Regarding your specific question: in a variable declaration, an asterisk means "this is a pointer":

  int * pointer;

It also describes function declarations / prototypes where variables are declared, as in your example.

After the declaration, an asterisk means that you are deleting the pointer. That is, you get the value in the place it points to.

  printf ("memory address:% d value:% d", pointer, * pointer);

You will notice that the memory address will change unexpectedly, depending on the state of the program when it is printed. In a simple program you will not see a change, but in a complex program you would.

+2
source share

All Articles