[lammps-users] a question about C++ grammar

Hi all,

I found the following codes in ‘lammps.h’ file:

class Memory ~~~
class ~~~~

I am wondering here that why we need ‘class’ here, as we know that, the ‘Memory’ has been defined elsewhere(memory.h) that it is a class name.

Thanks.

Hi all,

I found the following codes in 'lammps.h' file:

class Memory ~~~
class ~~~~

I am wondering here that why we need 'class' here, as we know that,
the 'Memory' has been defined elsewhere(memory.h) that it is a class
name.

it is a so-called 'forward declaration'. you need this to
tell the compiler that Memory is a class without having to
include the corresponding header that contains the full
definition. for as long as you only pass a pointer for that
class around, the full definition is not needed. this helps
to keep API header files small and also can be used to hide
the implementation details from the API definition.

for more detailed explanations, have a look into a book
on c/c++ language or ask in a forum on this topic.

cheers,
    axel.