-1

It might be a "dumb" question but i dont know what * do in that code.

ClassA* classa;

ClassA is a class, so what does the * actually do with a class? and how this ?operator? called?

user1888798
  • 229
  • 1
  • 2
  • 5

2 Answers2

1

* does not do anything with a class, it changes the type of the declared variable by making it a pointer:

ClassA *classa; // classa is a pointer to ClassA

You can add multiple asterisks to make pointers to pointers, pointers to pointers to pointers, and so on:

ClassA **classa; // classa is a pointer to pointer to ClassA
ClassA ***classa; // classa is a pointer to pointer to pointer to ClassA

Note that when the same asterisk is used in an expression (as opposed to a declaration) it "reduces" the level of a pointer, so

ClassA *classa;
foo(*classa); // Dereferences the pointer, producing ClassA
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

Pointer declaration.

After this declaration, classa is a variable with type "Pointer-to-a-ClassA object". It can point to any ClassA object, or any object that inherits from ClassA

abelenky
  • 63,815
  • 23
  • 109
  • 159