I am trying too read a code amd I encountered such a statement:
class Pointers {
public:
Pointers(LAMMPS *ptr) :
lmp(ptr),
logfile(ptr->logfile) {}
virtual ~Pointers() {}
protected:
LAMMPS *lmp;
};
I do not understand the use of ":" after "Pointers(LAMMPS *ptr)", what does it mean? What does it define?
Basically, it is used after constructors for classes to provide initializer lists for the class members.
Your class presumably has members called lmp and logfile. As you may know, when a class constructor is called, constructors are called for all its member variables. Usually in this situation, the default constructors of the members will be called.
However, if you want to call a constructor of a member variable with arguments, you do so by putting this colon ':' after the constructor.
So your code would result in the member lmp being initialized with the value ptr and the member logfile being initialized with the value ptr->logfile.