I have an object called Grid
which is evolving in my main script. This is how I have defined Grid
:
class Grid{
public:
std::vector <Polymer> PolymersInGrid; // all the polymers in the grid
std::vector <Particle> SolventInGrid; // solvent molecules in the grid
const int x; // length of x-edge of grid
const int y; // length of y-edge of grid
const int z; // length of z-edge of grid
const double kT; // energy factor
const double Emm ; // monomer-monomer interaction
const double Ess ; // solvent-solvent interaction
const double Ems_n ; // monomer-solvent when Not aligned
const double Ems_a ; // monomer-solvent when Aligned
double Energy;
std::map <std::vector <int>, Particle> OccupancyMap; // a map that gives the particle given the location
Grid(int xlen, int ylen, int zlen, double kT_, double Emm_, double Ess_, double Ems_n_, double Ems_a_): x (xlen), y (ylen), z (zlen), kT (kT_), Emm(Emm_), Ess (Ess_), Ems_n (Ems_n_), Ems_a (Ems_a_) { // Constructor of class
// this->instantiateOccupancyMap();
};
// Destructor of class
~Grid(){
};
...
};
In my main script, my Grid evolves when I apply an operator to Grid.
Grid G = CreateGridObject(positions, topology);
std::cout << "Energy of box is: " << G.Energy << std::endl;
for (int i{0}; i<NumberOfMoves; i++){
// perform evolution
Grid G_test (BackwardReptation(G, 0));
// check if G_test is a good structure
if (G_test is good){
// assign
G = G_test;
}
}
When I do this, I get the error
object of type 'Grid' cannot be assigned because its copy assignment operator is implicitly deleted. copy assignment operator of 'Grid' is implicitly deleted because field 'x' is of const-qualified type 'const int'
.
I need to evolve Grid multiple times, check if it is good at each evolution step, and change its contents. How can I do this given that I want the geometry of Grid and the energy surface (Emm, Ess, Ems_n, Ems_a
) are to be held const
?
edit: The following addition to my classobject worked:
Grid& operator=(const Grid& t){
return *this;
}
I understand that & is an overloaded operator, can be used to refer to addresses of variables, can be used for rvalues, lvalues. My question is, how does one read the syntax Grid& operator=
? What does Grid& mean?