3

I was reading the files in LAMMPS(An open source project),and come across this line of syntax

class FixPropertyGlobal* add_fix_property_global(int narg,char**arg,const char*);

in one of the .h file( Modify.h ) for a class declaration. My question is: Why add the keyword class in front of a seem-like member function? What does this syntax mean?

Zulu
  • 8,765
  • 9
  • 49
  • 56
slin6174
  • 108
  • 2
  • 10

1 Answers1

2

That is just a declaration of a global function, not a member function declaration.

That is equivalent to:

class FixPropertyGlobal;
FixPropertyGlobal* add_fix_property_global(int narg,char**arg,const char*);
R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • Thanks for the speedy response. Do you think I can ask you another question regarding debugging large open source project? I will open another thread on that in a bit. – slin6174 Jun 16 '14 at 05:16
  • @dl23lin you can certainly ask but a different SO post will be appropriate. – R Sahu Jun 16 '14 at 05:18
  • @dl23lin I understood what you meant. – R Sahu Jun 16 '14 at 05:23
  • 2
    Adding `class` is only necessary when the class hasn't been defined yet. It lets the compiler know that the function returns a pointer to some class called `FixPropertyGlobal` that will be defined later in the file. It still works if the class is defined, but is only necessary when it hasn't been. – Tyler Jun 16 '14 at 06:26
  • 1
    That's useful when, for example, you have a circular dependency where class A needs to have a member of class B and vice versa. AFAIK, whichever comes first (before the definition of the second) can only have a member of type class [second class]*. Where[second class] is the name of the second class. – Tyler Jun 16 '14 at 06:31
  • @Tyler These 2 comments should be an answer, one that clarifies the question. – mireazma Oct 19 '17 at 09:21