mardi 27 juin 2017

overloaded += operator with multiple terms

I have a two classes, a molecule and a single_atom class with overloaded operators +=, +, and *. + works as long as the two operands are a molecule or atom. * works with an atom or molecule and an int, and can be reversed. += only works when the operand is a single molecule or atom but should be able to evauluate complex expressions. How do I incorporate += so that the following works:

single_atom a1("sulpher");
single_atom a2("mercury");
Molecule m1(a1);
m1 += 3 * a1 + a2 * 4;

or even just:

m1 += 3 * a1;

Aucun commentaire:

Enregistrer un commentaire