double use of arrow pointers

Hi all,

I am trying to understand LAMMPS Molecular Dynamics package, in it, they use double use of arrow pointers like,

lammps->input->file();

Please help in this topic.

Thanks in advance.

regards,
baluu


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <mpi.h>
#include "lammps.h"
#include "input.h"
#include <stdio.h>

using namespace LAMMPS_NS;

int main(int argc, char **argv)
{
  MPI_Init(&argc,&argv);

  LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD);        


  lammps->input->file();
  delete lammps;

  MPI_Barrier(MPI_COMM_WORLD);
  MPI_Finalize();
}
Last edited on
Any pointer is accessed via the -> operator.

The struct/class LAMMPS has a member variable input which is a pointer and that's how you access that member variable.

If input had another member variable that is a pointer you would see lammps->input->another_pointer->whatever().

By the way: it is unnecessary to create an object with new and delete it within the same block of code. So alternatively:
1
2
3
4
  LAMMPS lammps(argc,argv,MPI_COMM_WORLD);        


  lammps.input->file(); // Note: lammps is not a pointer anymore 
Topic archived. No new replies allowed.