0

I've come across a declaration inside a C++ Struct{..} that I've never seen before. Can anyone tell me what it means;

struct DerivedMesh {

char cd_flag;

void (*calcNormals)(DerivedMesh *dm); // <-- What is this?

It kind of looks like it's dereferencing a pointer called calcNormals, but that's all I can make out.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
Fulcrum69
  • 1
  • 1

2 Answers2

2

This is a C syntax for declaring function pointers.

In this particular example, DerivedMesh will have a member calcNormals that is a pointer to a function accepting single argument of type DerivedMesh*. It can be called like an ordinary function:

void foo(DerivedMesh* dm) { ... }

DerivedMesh dm;;
// Init members and set calcNormals to actual function
dm.cf_flag = whatever;
dm.calcNormals = foo;
dm.calcNormals(&dm); // calls foo
Andrey
  • 1,561
  • 9
  • 12
0

This

void (*calcNormals)(DerivedMesh *dm); 

is class data member definition with name calcNormals that has type of pointer to function of type void( DerivedMesh * )

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335